tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_nothrow_constructible.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_HPP
5#define TETL_TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_type_traits/bool_constant.hpp>
10#include <etl/_type_traits/declval.hpp>
11#include <etl/_type_traits/remove_all_extents.hpp>
12
13namespace etl {
14
15namespace detail {
16template <bool, typename T, typename... Args>
17struct nothrow_constructible_impl : false_type { };
18
19template <typename T, typename... Args>
20struct nothrow_constructible_impl<true, T, Args...> : bool_constant<noexcept(T(declval<Args>()...))> { };
21
22template <typename T, typename Arg>
23struct nothrow_constructible_impl<true, T, Arg> : bool_constant<noexcept(static_cast<T>(declval<Arg>()))> { };
24
25template <typename T>
26struct nothrow_constructible_impl<true, T> : bool_constant<noexcept(T())> { };
27
28template <typename T, size_t Size>
29struct nothrow_constructible_impl<true, T[Size]> : bool_constant<noexcept(remove_all_extents_t<T>())> { };
30
31#if defined(__cpp_aggregate_paren_init)
32template <typename T, size_t Size, typename Arg>
33struct nothrow_constructible_impl<true, T[Size], Arg> : nothrow_constructible_impl<true, T, Arg> { };
34
35template <typename T, size_t Size, typename... Args>
36struct nothrow_constructible_impl<true, T[Size], Args...>
37 : bool_constant<(nothrow_constructible_impl<true, T, Args>::value && ...)> { };
38#endif
39
40template <typename T, typename... Args>
41using is_nothrow_constructible_helper = nothrow_constructible_impl<__is_constructible(T, Args...), T, Args...>;
42} // namespace detail
43
44/// \brief The variable definition does not call any operation that is not
45/// trivial. For the purposes of this check, the call to etl::declval is
46/// considered trivial.
47template <typename T, typename... Args>
48struct is_nothrow_constructible : detail::is_nothrow_constructible_helper<T, Args...>::type { };
49
50template <typename T, typename... Args>
52
53} // namespace etl
54
55#endif // TETL_TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_HPP
Definition adjacent_find.hpp:9
constexpr bool is_nothrow_constructible_v
Definition is_nothrow_constructible.hpp:51
The variable definition does not call any operation that is not trivial. For the purposes of this che...
Definition is_nothrow_constructible.hpp:48