diff --git a/linux/include/concepts/compare.hpp b/linux/include/concepts/compare.hpp new file mode 100644 index 000000000..4b0beb8d5 --- /dev/null +++ b/linux/include/concepts/compare.hpp @@ -0,0 +1,65 @@ +/// \file +// CPP, the Concepts PreProcessor library +// +// Copyright Eric Niebler 2018-present +// Copyright (c) 2020-present, Google LLC. +// +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. +// +// Project home: https://github.com/ericniebler/range-v3 +// +#ifndef CPP_COMPARE_HPP +#define CPP_COMPARE_HPP + +#if __cplusplus > 201703L && defined(__cpp_impl_three_way_comparison) && __has_include() + +#include +#include +#include + +// clang-format off + +namespace concepts +{ + // Note: concepts in this file can use C++20 concepts, since operator<=> isn't available in + // compilers that don't support core concepts. + namespace detail + { + template + concept compares_as = same_as, Cat>; + } // namespace detail + + inline namespace defs + { + template + concept three_way_comparable = + detail::weakly_equality_comparable_with_ && + detail::partially_ordered_with_ && + requires(detail::as_cref_t& a, detail::as_cref_t& b) { + { a <=> b } -> detail::compares_as; + }; + + template + concept three_way_comparable_with = + three_way_comparable && + three_way_comparable && + common_reference_with&, detail::as_cref_t&> && + three_way_comparable&, detail::as_cref_t&>> && + detail::partially_ordered_with_ && + requires(detail::as_cref_t& t, detail::as_cref_t& u) { + { t <=> u } -> detail::compares_as; + { u <=> t } -> detail::compares_as; + }; + } // inline namespace defs +} // namespace concepts + +// clang-format on + +#endif // __cplusplus +#endif // CPP_COMPARE_HPP diff --git a/linux/include/concepts/concepts.hpp b/linux/include/concepts/concepts.hpp new file mode 100644 index 000000000..a1c3182c1 --- /dev/null +++ b/linux/include/concepts/concepts.hpp @@ -0,0 +1,1136 @@ +/// \file +// CPP, the Concepts PreProcessor library +// +// Copyright Eric Niebler 2018-present +// Copyright (c) 2018-present, Facebook, Inc. +// Copyright (c) 2020-present, Google LLC. +// +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. +// +// Project home: https://github.com/ericniebler/range-v3 +// + +#ifndef CPP_CONCEPTS_HPP +#define CPP_CONCEPTS_HPP + +// clang-format off + +#include +#include +#include +#include +#include + +// Disable buggy clang compatibility warning about "requires" and "concept" being +// C++20 keywords. +// https://bugs.llvm.org/show_bug.cgi?id=43708 +#if defined(__clang__) && __cplusplus <= 201703L +#define CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ + CPP_DIAGNOSTIC_PUSH \ + CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT + +#define CPP_PP_IGNORE_CXX2A_COMPAT_END \ + CPP_DIAGNOSTIC_POP + +#else +#define CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN +#define CPP_PP_IGNORE_CXX2A_COMPAT_END +#endif + +#if defined(_MSC_VER) && !defined(__clang__) +#define CPP_WORKAROUND_MSVC_779763 // FATAL_UNREACHABLE calling constexpr function via template parameter +#define CPP_WORKAROUND_MSVC_784772 // Failure to invoke *explicit* bool conversion in a constant expression +#endif + +#if !defined(CPP_CXX_CONCEPTS) +#ifdef CPP_DOXYGEN_INVOKED +#define CPP_CXX_CONCEPTS 201800L +#elif defined(__cpp_concepts) && __cpp_concepts > 0 +// gcc-6 concepts are too buggy to use +#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 7 +#define CPP_CXX_CONCEPTS __cpp_concepts +#else +#define CPP_CXX_CONCEPTS 0L +#endif +#else +#define CPP_CXX_CONCEPTS 0L +#endif +#endif + +#define CPP_PP_CAT_(X, ...) X ## __VA_ARGS__ +#define CPP_PP_CAT(X, ...) CPP_PP_CAT_(X, __VA_ARGS__) + +#define CPP_PP_EVAL_(X, ARGS) X ARGS +#define CPP_PP_EVAL(X, ...) CPP_PP_EVAL_(X, (__VA_ARGS__)) + +#define CPP_PP_EVAL2_(X, ARGS) X ARGS +#define CPP_PP_EVAL2(X, ...) CPP_PP_EVAL2_(X, (__VA_ARGS__)) + +#define CPP_PP_EXPAND(...) __VA_ARGS__ +#define CPP_PP_EAT(...) + +#define CPP_PP_FIRST(LIST) CPP_PP_FIRST_ LIST +#define CPP_PP_FIRST_(...) __VA_ARGS__ CPP_PP_EAT + +#define CPP_PP_SECOND(LIST) CPP_PP_SECOND_ LIST +#define CPP_PP_SECOND_(...) CPP_PP_EXPAND + +#define CPP_PP_CHECK(...) CPP_PP_EXPAND(CPP_PP_CHECK_N(__VA_ARGS__, 0,)) +#define CPP_PP_CHECK_N(x, n, ...) n +#define CPP_PP_PROBE(x) x, 1, +#define CPP_PP_PROBE_N(x, n) x, n, + +#define CPP_PP_IS_PAREN(x) CPP_PP_CHECK(CPP_PP_IS_PAREN_PROBE x) +#define CPP_PP_IS_PAREN_PROBE(...) CPP_PP_PROBE(~) + +// CPP_CXX_VA_OPT +#ifndef CPP_CXX_VA_OPT +#if __cplusplus > 201703L +#define CPP_CXX_VA_OPT_(...) CPP_PP_CHECK(__VA_OPT__(,) 1) +#define CPP_CXX_VA_OPT CPP_CXX_VA_OPT_(~) +#else +#define CPP_CXX_VA_OPT 0 +#endif +#endif // CPP_CXX_VA_OPT + +// The final CPP_PP_EXPAND here is to avoid +// https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly +#define CPP_PP_COUNT(...) \ + CPP_PP_EXPAND(CPP_PP_COUNT_(__VA_ARGS__, \ + 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ + 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ + 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ + 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)) + +#define CPP_PP_COUNT_( \ + _01, _02, _03, _04, _05, _06, _07, _08, _09, _10, \ + _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ + _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ + _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ + _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, N, ...) \ + N + +#define CPP_PP_IIF(BIT) CPP_PP_CAT_(CPP_PP_IIF_, BIT) +#define CPP_PP_IIF_0(TRUE, ...) __VA_ARGS__ +#define CPP_PP_IIF_1(TRUE, ...) TRUE + +#define CPP_PP_LPAREN ( +#define CPP_PP_RPAREN ) + +#define CPP_PP_NOT(BIT) CPP_PP_CAT_(CPP_PP_NOT_, BIT) +#define CPP_PP_NOT_0 1 +#define CPP_PP_NOT_1 0 + +#define CPP_PP_EMPTY() +#define CPP_PP_COMMA() , +#define CPP_PP_LBRACE() { +#define CPP_PP_RBRACE() } +#define CPP_PP_COMMA_IIF(X) \ + CPP_PP_IIF(X)(CPP_PP_EMPTY, CPP_PP_COMMA)() + +#define CPP_PP_FOR_EACH(M, ...) \ + CPP_PP_FOR_EACH_N(CPP_PP_COUNT(__VA_ARGS__), M, __VA_ARGS__) +#define CPP_PP_FOR_EACH_N(N, M, ...) \ + CPP_PP_CAT(CPP_PP_FOR_EACH_, N)(M, __VA_ARGS__) +#define CPP_PP_FOR_EACH_1(M, _1) \ + M(_1) +#define CPP_PP_FOR_EACH_2(M, _1, _2) \ + M(_1), M(_2) +#define CPP_PP_FOR_EACH_3(M, _1, _2, _3) \ + M(_1), M(_2), M(_3) +#define CPP_PP_FOR_EACH_4(M, _1, _2, _3, _4) \ + M(_1), M(_2), M(_3), M(_4) +#define CPP_PP_FOR_EACH_5(M, _1, _2, _3, _4, _5) \ + M(_1), M(_2), M(_3), M(_4), M(_5) +#define CPP_PP_FOR_EACH_6(M, _1, _2, _3, _4, _5, _6) \ + M(_1), M(_2), M(_3), M(_4), M(_5), M(_6) +#define CPP_PP_FOR_EACH_7(M, _1, _2, _3, _4, _5, _6, _7) \ + M(_1), M(_2), M(_3), M(_4), M(_5), M(_6), M(_7) +#define CPP_PP_FOR_EACH_8(M, _1, _2, _3, _4, _5, _6, _7, _8) \ + M(_1), M(_2), M(_3), M(_4), M(_5), M(_6), M(_7), M(_8) + +#define CPP_PP_PROBE_EMPTY_PROBE_CPP_PP_PROBE_EMPTY \ + CPP_PP_PROBE(~) + +#define CPP_PP_PROBE_EMPTY() +#define CPP_PP_IS_NOT_EMPTY(...) \ + CPP_PP_EVAL( \ + CPP_PP_CHECK, \ + CPP_PP_CAT( \ + CPP_PP_PROBE_EMPTY_PROBE_, \ + CPP_PP_PROBE_EMPTY __VA_ARGS__ ())) + +#if defined(_MSC_VER) && !defined(__clang__) && (__cplusplus <= 201703L) +#define CPP_BOOL(...) ::meta::bool_<__VA_ARGS__>::value +#define CPP_TRUE_FN \ + !::concepts::detail::instance_< \ + decltype(CPP_true_fn(::concepts::detail::xNil{}))> + +#define CPP_NOT(...) (!CPP_BOOL(__VA_ARGS__)) +#else +#define CPP_BOOL(...) __VA_ARGS__ +#define CPP_TRUE_FN CPP_true_fn(::concepts::detail::xNil{}) +#define CPP_NOT(...) (!(__VA_ARGS__)) +#endif + +#define CPP_assert(...) \ + static_assert(static_cast(__VA_ARGS__), \ + "Concept assertion failed : " #__VA_ARGS__) + +#define CPP_assert_msg static_assert + +#if CPP_CXX_CONCEPTS || defined(CPP_DOXYGEN_INVOKED) +#define CPP_concept META_CONCEPT +#define CPP_and && + +#else +#define CPP_concept CPP_INLINE_VAR constexpr bool +#define CPP_and CPP_and_sfinae + +#endif + +//////////////////////////////////////////////////////////////////////////////// +// CPP_template +// Usage: +// CPP_template(typename A, typename B) +// (requires Concept1 CPP_and Concept2) +// void foo(A a, B b) +// {} +#if CPP_CXX_CONCEPTS +#define CPP_template(...) template<__VA_ARGS__ CPP_TEMPLATE_AUX_ +#define CPP_template_def CPP_template +#define CPP_member +#define CPP_ctor(TYPE) TYPE CPP_CTOR_IMPL_1_ +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 10 +#define CPP_auto_member template +#else +#define CPP_auto_member +#endif + +#if defined(CPP_DOXYGEN_INVOKED) && CPP_DOXYGEN_INVOKED +/// INTERNAL ONLY +#define CPP_CTOR_IMPL_1_(...) (__VA_ARGS__) CPP_CTOR_IMPL_2_ +#define CPP_CTOR_IMPL_2_(...) __VA_ARGS__ ` +#else +/// INTERNAL ONLY +#define CPP_CTOR_IMPL_1_(...) (__VA_ARGS__) CPP_PP_EXPAND +#endif + +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_(...) \ + > CPP_PP_CAT( \ + CPP_TEMPLATE_AUX_, \ + CPP_TEMPLATE_AUX_WHICH_(__VA_ARGS__,))(__VA_ARGS__) + +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_WHICH_(FIRST, ...) \ + CPP_PP_EVAL( \ + CPP_PP_CHECK, \ + CPP_PP_CAT(CPP_TEMPLATE_PROBE_CONCEPT_, FIRST)) + +/// INTERNAL ONLY +#define CPP_TEMPLATE_PROBE_CONCEPT_concept \ + CPP_PP_PROBE(~) + +#if defined(CPP_DOXYGEN_INVOKED) && CPP_DOXYGEN_INVOKED +// A template with a requires clause. Turn the requires clause into +// a Doxygen precondition block. +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_0(...) __VA_ARGS__` +#define requires requires ` + +#else +// A template with a requires clause +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_0(...) __VA_ARGS__ +#endif + +// A concept definition +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_1(DECL, ...) \ + CPP_concept CPP_CONCEPT_NAME_(DECL) = __VA_ARGS__ + +#define CPP_concept_ref(NAME, ...) \ + CPP_PP_CAT(NAME, _concept_)<__VA_ARGS__> + +#else // ^^^^ with concepts / without concepts vvvv + +#define CPP_template CPP_template_sfinae +#define CPP_template_def CPP_template_def_sfinae +#define CPP_member CPP_member_sfinae +#define CPP_auto_member CPP_member_sfinae +#define CPP_ctor CPP_ctor_sfinae +#define CPP_concept_ref(NAME, ...) \ + (1u == sizeof(CPP_PP_CAT(NAME, _concept_)( \ + (::concepts::detail::tag<__VA_ARGS__>*)nullptr))) + +/// INTERNAL ONLY +#define CPP_TEMPLATE_AUX_ CPP_TEMPLATE_SFINAE_AUX_ + +#endif + +#define CPP_template_sfinae(...) \ + CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ + template<__VA_ARGS__ CPP_TEMPLATE_SFINAE_AUX_ + +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_PROBE_CONCEPT_concept \ + CPP_PP_PROBE(~) + +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_AUX_WHICH_(FIRST, ...) \ + CPP_PP_EVAL( \ + CPP_PP_CHECK, \ + CPP_PP_CAT(CPP_TEMPLATE_SFINAE_PROBE_CONCEPT_, FIRST)) + +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_AUX_(...) \ + CPP_PP_CAT( \ + CPP_TEMPLATE_SFINAE_AUX_, \ + CPP_TEMPLATE_SFINAE_AUX_WHICH_(__VA_ARGS__,))(__VA_ARGS__) + +// A template with a requires clause +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_AUX_0(...) , \ + bool CPP_true = true, \ + std::enable_if_t< \ + CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && \ + CPP_BOOL(CPP_true), \ + int> = 0> \ + CPP_PP_IGNORE_CXX2A_COMPAT_END + +// A concept definition +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_AUX_1(DECL, ...) , \ + bool CPP_true = true, \ + std::enable_if_t<__VA_ARGS__ && CPP_BOOL(CPP_true), int> = 0> \ + auto CPP_CONCEPT_NAME_(DECL)( \ + ::concepts::detail::tag*) \ + -> char(&)[1]; \ + auto CPP_CONCEPT_NAME_(DECL)(...) -> char(&)[2] \ + CPP_PP_IGNORE_CXX2A_COMPAT_END + +/// INTERNAL ONLY +#define CPP_CONCEPT_NAME_(DECL) \ + CPP_PP_EVAL( \ + CPP_PP_CAT, \ + CPP_PP_EVAL(CPP_PP_FIRST, CPP_EAT_CONCEPT_(DECL)), _concept_) + +/// INTERNAL ONLY +#define CPP_CONCEPT_PARAMS_(DECL) \ + CPP_PP_EVAL(CPP_PP_SECOND, CPP_EAT_CONCEPT_(DECL)) + +/// INTERNAL ONLY +#define CPP_EAT_CONCEPT_(DECL) \ + CPP_PP_CAT(CPP_EAT_CONCEPT_, DECL) + +/// INTERNAL ONLY +#define CPP_EAT_CONCEPT_concept + +#define CPP_and_sfinae \ + && CPP_BOOL(CPP_true), int> = 0, std::enable_if_t< + +#define CPP_template_def_sfinae(...) \ + template<__VA_ARGS__ CPP_TEMPLATE_DEF_SFINAE_AUX_ + +/// INTERNAL ONLY +#define CPP_TEMPLATE_DEF_SFINAE_AUX_(...) , \ + bool CPP_true, \ + std::enable_if_t< \ + CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && \ + CPP_BOOL(CPP_true), \ + int>> + +#define CPP_and_sfinae_def \ + && CPP_BOOL(CPP_true), int>, std::enable_if_t< + +/// INTERNAL ONLY +#define CPP_TEMPLATE_SFINAE_AUX_3_requires + +#define CPP_member_sfinae \ + CPP_broken_friend_member + +#define CPP_ctor_sfinae(TYPE) \ + CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ + TYPE CPP_CTOR_SFINAE_IMPL_1_ + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_IMPL_1_(...) \ + (__VA_ARGS__ \ + CPP_PP_COMMA_IIF( \ + CPP_PP_NOT(CPP_PP_IS_NOT_EMPTY(__VA_ARGS__))) \ + CPP_CTOR_SFINAE_REQUIRES + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_PROBE_NOEXCEPT_noexcept \ + CPP_PP_PROBE(~) + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_MAKE_PROBE(FIRST,...) \ + CPP_PP_CAT(CPP_CTOR_SFINAE_PROBE_NOEXCEPT_, FIRST) + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_REQUIRES(...) \ + CPP_PP_CAT( \ + CPP_CTOR_SFINAE_REQUIRES_, \ + CPP_PP_EVAL( \ + CPP_PP_CHECK, \ + CPP_CTOR_SFINAE_MAKE_PROBE(__VA_ARGS__,)))(__VA_ARGS__) + +// No noexcept-clause: +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_REQUIRES_0(...) \ + std::enable_if_t< \ + CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && CPP_TRUE_FN, \ + ::concepts::detail::Nil \ + > = {}) \ + CPP_PP_IGNORE_CXX2A_COMPAT_END + +// Yes noexcept-clause: +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_REQUIRES_1(...) \ + std::enable_if_t< \ + CPP_PP_EVAL(CPP_PP_CAT, \ + CPP_TEMPLATE_SFINAE_AUX_3_, \ + CPP_PP_CAT(CPP_CTOR_SFINAE_EAT_NOEXCEPT_, __VA_ARGS__)) && CPP_TRUE_FN,\ + ::concepts::detail::Nil \ + > = {}) \ + CPP_PP_EXPAND(CPP_PP_CAT(CPP_CTOR_SFINAE_SHOW_NOEXCEPT_, __VA_ARGS__))) + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_EAT_NOEXCEPT_noexcept(...) + +/// INTERNAL ONLY +#define CPP_CTOR_SFINAE_SHOW_NOEXCEPT_noexcept(...) \ + noexcept(__VA_ARGS__) \ + CPP_PP_IGNORE_CXX2A_COMPAT_END \ + CPP_PP_EAT CPP_PP_LPAREN + +#ifdef CPP_DOXYGEN_INVOKED +#define CPP_broken_friend_ret(...) \ + __VA_ARGS__ CPP_PP_EXPAND + +#else // ^^^ CPP_DOXYGEN_INVOKED / not CPP_DOXYGEN_INVOKED vvv +#define CPP_broken_friend_ret(...) \ + ::concepts::return_t< \ + __VA_ARGS__, \ + std::enable_if_t> + +#ifdef CPP_WORKAROUND_MSVC_779763 +#define CPP_broken_friend_member \ + template<::concepts::detail::CPP_true_t const &CPP_true_fn = \ + ::concepts::detail::CPP_true_fn_> + +#else // ^^^ workaround / no workaround vvv +#define CPP_broken_friend_member \ + template + +#endif // CPP_WORKAROUND_MSVC_779763 +#endif + +#if CPP_CXX_CONCEPTS +#define CPP_requires(NAME, REQS) \ +CPP_concept CPP_PP_CAT(NAME, _requires_) = \ + CPP_PP_CAT(CPP_REQUIRES_, REQS) + +#define CPP_requires_ref(NAME, ...) \ + CPP_PP_CAT(NAME, _requires_)<__VA_ARGS__> + +/// INTERNAL ONLY +#define CPP_REQUIRES_requires(...) \ + requires(__VA_ARGS__) CPP_REQUIRES_AUX_ + +/// INTERNAL ONLY +#define CPP_REQUIRES_AUX_(...) \ + { __VA_ARGS__; } + +#else +#define CPP_requires(NAME, REQS) \ + auto CPP_PP_CAT(NAME, _requires_test_) \ + CPP_REQUIRES_AUX_(NAME, CPP_REQUIRES_ ## REQS) + +#define CPP_requires_ref(NAME, ...) \ + (1u == sizeof(CPP_PP_CAT(NAME, _requires_)( \ + (::concepts::detail::tag<__VA_ARGS__>*)nullptr))) + +/// INTERNAL ONLY +#define CPP_REQUIRES_requires(...) \ + (__VA_ARGS__) -> decltype CPP_REQUIRES_RETURN_ + +/// INTERNAL ONLY +#define CPP_REQUIRES_RETURN_(...) (__VA_ARGS__, void()) {} + +/// INTERNAL ONLY +#define CPP_REQUIRES_AUX_(NAME, ...) \ + __VA_ARGS__ \ + template \ + auto CPP_PP_CAT(NAME, _requires_)( \ + ::concepts::detail::tag *, \ + decltype(&CPP_PP_CAT(NAME, _requires_test_)) = nullptr) \ + -> char(&)[1]; \ + auto CPP_PP_CAT(NAME, _requires_)(...) -> char(&)[2] + +#endif + +#if CPP_CXX_CONCEPTS + +#if defined(CPP_DOXYGEN_INVOKED) && CPP_DOXYGEN_INVOKED +#define CPP_ret(...) \ + __VA_ARGS__ CPP_RET_AUX_ +#define CPP_RET_AUX_(...) __VA_ARGS__ ` +#else +#define CPP_ret(...) \ + __VA_ARGS__ CPP_PP_EXPAND +#endif + +#else +#define CPP_ret \ + CPP_broken_friend_ret + +#endif + +//////////////////////////////////////////////////////////////////////////////// +// CPP_fun +#if CPP_CXX_CONCEPTS + +#if defined(CPP_DOXYGEN_INVOKED) && CPP_DOXYGEN_INVOKED +/// INTERNAL ONLY +#define CPP_FUN_IMPL_1_(...) \ + (__VA_ARGS__) \ + CPP_FUN_IMPL_2_ +#define CPP_FUN_IMPL_2_(...) \ + __VA_ARGS__ ` +#else +/// INTERNAL ONLY +#define CPP_FUN_IMPL_1_(...) \ + (__VA_ARGS__) \ + CPP_PP_EXPAND +#endif + +#define CPP_fun(X) X CPP_FUN_IMPL_1_ +#else +/// INTERNAL ONLY +#define CPP_FUN_IMPL_1_(...) \ + (__VA_ARGS__ \ + CPP_PP_COMMA_IIF( \ + CPP_PP_NOT(CPP_PP_IS_NOT_EMPTY(__VA_ARGS__))) \ + CPP_FUN_IMPL_REQUIRES + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_REQUIRES(...) \ + CPP_PP_EVAL2_( \ + CPP_FUN_IMPL_SELECT_CONST_, \ + (__VA_ARGS__,) \ + )(__VA_ARGS__) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_(MAYBE_CONST, ...) \ + CPP_PP_CAT(CPP_FUN_IMPL_SELECT_CONST_, \ + CPP_PP_EVAL(CPP_PP_CHECK, CPP_PP_CAT( \ + CPP_PP_PROBE_CONST_PROBE_, MAYBE_CONST))) + +/// INTERNAL ONLY +#define CPP_PP_PROBE_CONST_PROBE_const CPP_PP_PROBE(~) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_1(...) \ + CPP_PP_EVAL( \ + CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_, \ + CPP_PP_CAT(CPP_FUN_IMPL_EAT_CONST_, __VA_ARGS__),)( \ + CPP_PP_CAT(CPP_FUN_IMPL_EAT_CONST_, __VA_ARGS__)) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_(MAYBE_NOEXCEPT, ...) \ + CPP_PP_CAT(CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_, \ + CPP_PP_EVAL2(CPP_PP_CHECK, CPP_PP_CAT( \ + CPP_PP_PROBE_NOEXCEPT_PROBE_, MAYBE_NOEXCEPT))) + +/// INTERNAL ONLY +#define CPP_PP_PROBE_NOEXCEPT_PROBE_noexcept CPP_PP_PROBE(~) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_0(...) \ + std::enable_if_t< \ + CPP_PP_EVAL( \ + CPP_PP_CAT, \ + CPP_FUN_IMPL_EAT_REQUIRES_, \ + __VA_ARGS__) && CPP_TRUE_FN, \ + ::concepts::detail::Nil \ + > = {}) const \ + CPP_PP_IGNORE_CXX2A_COMPAT_END + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_1(...) \ + std::enable_if_t< \ + CPP_PP_EVAL( \ + CPP_PP_CAT, \ + CPP_FUN_IMPL_EAT_REQUIRES_, \ + CPP_PP_CAT(CPP_FUN_IMPL_EAT_NOEXCEPT_, __VA_ARGS__)) && CPP_TRUE_FN, \ + ::concepts::detail::Nil \ + > = {}) const \ + CPP_PP_EXPAND(CPP_PP_CAT(CPP_FUN_IMPL_SHOW_NOEXCEPT_, __VA_ARGS__))) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_EAT_NOEXCEPT_noexcept(...) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SHOW_NOEXCEPT_noexcept(...) \ + noexcept(__VA_ARGS__) CPP_PP_IGNORE_CXX2A_COMPAT_END \ + CPP_PP_EAT CPP_PP_LPAREN + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_CONST_0(...) \ + CPP_PP_EVAL_( \ + CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_, \ + (__VA_ARGS__,) \ + )(__VA_ARGS__) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_(MAYBE_NOEXCEPT, ...) \ + CPP_PP_CAT(CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_, \ + CPP_PP_EVAL2(CPP_PP_CHECK, CPP_PP_CAT( \ + CPP_PP_PROBE_NOEXCEPT_PROBE_, MAYBE_NOEXCEPT))) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_0(...) \ + std::enable_if_t< \ + CPP_PP_CAT(CPP_FUN_IMPL_EAT_REQUIRES_, __VA_ARGS__) && CPP_TRUE_FN, \ + ::concepts::detail::Nil \ + > = {}) \ + CPP_PP_IGNORE_CXX2A_COMPAT_END + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_1(...) \ + std::enable_if_t< \ + CPP_PP_EVAL( \ + CPP_PP_CAT, \ + CPP_FUN_IMPL_EAT_REQUIRES_, \ + CPP_PP_CAT(CPP_FUN_IMPL_EAT_NOEXCEPT_, __VA_ARGS__) \ + ) && CPP_TRUE_FN, \ + ::concepts::detail::Nil \ + > = {}) \ + CPP_PP_EXPAND(CPP_PP_CAT(CPP_FUN_IMPL_SHOW_NOEXCEPT_, __VA_ARGS__))) + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_EAT_CONST_const + +/// INTERNAL ONLY +#define CPP_FUN_IMPL_EAT_REQUIRES_requires + +//////////////////////////////////////////////////////////////////////////////// +// CPP_fun +// Usage: +// template +// void CPP_fun(foo)(A a, B b)([const]opt [noexcept(true)]opt +// requires Concept1 && Concept2) +// {} +// +// Note: This macro cannot be used when the last function argument is a +// parameter pack. +#define CPP_fun(X) CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN X CPP_FUN_IMPL_1_ +#endif + +//////////////////////////////////////////////////////////////////////////////// +// CPP_auto_fun +// Usage: +// template +// auto CPP_auto_fun(foo)(A a, B b)([const]opt [noexcept(cond)]opt)opt +// ( +// return a + b +// ) +#define CPP_auto_fun(X) X CPP_AUTO_FUN_IMPL_ + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_IMPL_(...) (__VA_ARGS__) CPP_AUTO_FUN_RETURNS_ + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_RETURNS_(...) \ + CPP_PP_EVAL2_( \ + CPP_AUTO_FUN_SELECT_RETURNS_, \ + (__VA_ARGS__,) \ + )(__VA_ARGS__) + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_SELECT_RETURNS_(MAYBE_CONST, ...) \ + CPP_PP_CAT(CPP_AUTO_FUN_RETURNS_CONST_, \ + CPP_PP_EVAL(CPP_PP_CHECK, CPP_PP_CAT( \ + CPP_PP_PROBE_CONST_MUTABLE_PROBE_, MAYBE_CONST))) + +/// INTERNAL ONLY +#define CPP_PP_PROBE_CONST_MUTABLE_PROBE_const CPP_PP_PROBE_N(~, 1) + +/// INTERNAL ONLY +#define CPP_PP_PROBE_CONST_MUTABLE_PROBE_mutable CPP_PP_PROBE_N(~, 2) + +/// INTERNAL ONLY +#define CPP_PP_EAT_MUTABLE_mutable + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_RETURNS_CONST_2(...) \ + CPP_PP_CAT(CPP_PP_EAT_MUTABLE_, __VA_ARGS__) CPP_AUTO_FUN_RETURNS_CONST_0 + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_RETURNS_CONST_1(...) \ + __VA_ARGS__ CPP_AUTO_FUN_RETURNS_CONST_0 + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_RETURNS_CONST_0(...) \ + CPP_PP_EVAL(CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_, \ + CPP_PP_CAT(CPP_AUTO_FUN_RETURNS_, __VA_ARGS__)) + +/// INTERNAL ONLY +#define CPP_AUTO_FUN_RETURNS_return + +#ifdef __cpp_guaranteed_copy_elision +/// INTERNAL ONLY +#define CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_(...) \ + noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \ + { return (__VA_ARGS__); } + +#else +/// INTERNAL ONLY +#define CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_(...) \ + noexcept(noexcept(decltype(__VA_ARGS__)(__VA_ARGS__))) -> \ + decltype(__VA_ARGS__) \ + { return (__VA_ARGS__); } + +#endif + +namespace concepts +{ + template + using bool_ = std::integral_constant; + +#if defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603 + template + CPP_INLINE_VAR constexpr bool and_v = (Bs &&...); + + template + CPP_INLINE_VAR constexpr bool or_v = (Bs ||...); +#else + namespace detail + { + template + struct bools; + } // namespace detail + + template + CPP_INLINE_VAR constexpr bool and_v = + META_IS_SAME(detail::bools, detail::bools); + + template + CPP_INLINE_VAR constexpr bool or_v = + !META_IS_SAME(detail::bools, detail::bools); +#endif + + template + struct return_t_ + { + template + using invoke = T; + }; + + template + using return_t = meta::invoke, T>; + + namespace detail + { + struct ignore + { + template + constexpr ignore(Args&&...) noexcept {} + }; + + template + constexpr bool true_() + { + return true; + } + + template + struct tag; + + template + CPP_INLINE_VAR constexpr T instance_ = T{}; + + template + constexpr bool requires_() + { + return true; + } + + struct Nil + {}; + +#ifdef CPP_WORKAROUND_MSVC_779763 + enum class xNil {}; + + struct CPP_true_t + { + constexpr bool operator()(Nil) const noexcept + { + return true; + } + constexpr bool operator()(xNil) const noexcept + { + return true; + } + }; + + CPP_INLINE_VAR constexpr CPP_true_t CPP_true_fn_ {}; + + constexpr bool CPP_true_fn(xNil) + { + return true; + } +#else + using xNil = Nil; +#endif + + constexpr bool CPP_true_fn(Nil) + { + return true; + } + } // namespace detail + +#if defined(__clang__) || defined(_MSC_VER) + template + std::enable_if_t requires_() + {} +#else + template + CPP_INLINE_VAR constexpr std::enable_if_t requires_ = 0; +#endif + + inline namespace defs + { + //////////////////////////////////////////////////////////////////////// + // Utility concepts + //////////////////////////////////////////////////////////////////////// + + template + CPP_concept is_true = B; + + template + CPP_concept type = true; + + template class Trait, typename... Args> + CPP_concept satisfies = + static_cast(Trait::type::value); + + //////////////////////////////////////////////////////////////////////// + // Core language concepts + //////////////////////////////////////////////////////////////////////// + + template + CPP_concept same_as = + META_IS_SAME(A, B) && META_IS_SAME(B, A); + + /// \cond + template + CPP_concept not_same_as_ = + (!same_as, remove_cvref_t>); + + // Workaround bug in the Standard Library: + // From cannot be an incomplete class type despite that + // is_convertible should be equivalent to is_convertible + // in such a case. + template + CPP_concept implicitly_convertible_to = + std::is_convertible, To>::value; + + template + CPP_requires(explicitly_convertible_to_, + requires(From(*from)()) // + ( + static_cast(from()) + )); + template + CPP_concept explicitly_convertible_to = + CPP_requires_ref(concepts::explicitly_convertible_to_, From, To); + /// \endcond + + template + CPP_concept convertible_to = + implicitly_convertible_to && + explicitly_convertible_to; + + CPP_template(typename T, typename U)( + concept (derived_from_)(T, U), + convertible_to + ); + template + CPP_concept derived_from = + META_IS_BASE_OF(U, T) && + CPP_concept_ref(concepts::derived_from_, T, U); + + CPP_template(typename T, typename U)( + concept (common_reference_with_)(T, U), + same_as, common_reference_t> CPP_and + convertible_to> CPP_and + convertible_to> + ); + template + CPP_concept common_reference_with = + CPP_concept_ref(concepts::common_reference_with_, T, U); + + CPP_template(typename T, typename U)( + concept (common_with_)(T, U), + same_as, common_type_t> CPP_and + convertible_to> CPP_and + convertible_to> CPP_and + common_reference_with< + std::add_lvalue_reference_t, + std::add_lvalue_reference_t> CPP_and + common_reference_with< + std::add_lvalue_reference_t>, + common_reference_t< + std::add_lvalue_reference_t, + std::add_lvalue_reference_t>> + ); + template + CPP_concept common_with = + CPP_concept_ref(concepts::common_with_, T, U); + + template + CPP_concept integral = + std::is_integral::value; + + template + CPP_concept signed_integral = + integral && + std::is_signed::value; + + template + CPP_concept unsigned_integral = + integral && + !signed_integral; + + template + CPP_requires(assignable_from_, + requires(T t, U && u) // + ( + t = (U &&) u, + requires_> + )); + template + CPP_concept assignable_from = + std::is_lvalue_reference::value && + common_reference_with, detail::as_cref_t> && + CPP_requires_ref(defs::assignable_from_, T, U); + + template + CPP_requires(swappable_, + requires(T & t, T & u) // + ( + concepts::swap(t, u) + )); + template + CPP_concept swappable = + CPP_requires_ref(defs::swappable_, T); + + template + CPP_requires(swappable_with_, + requires(T && t, U && u) // + ( + concepts::swap((T &&) t, (T &&) t), + concepts::swap((U &&) u, (U &&) u), + concepts::swap((U &&) u, (T &&) t), + concepts::swap((T &&) t, (U &&) u) + )); + template + CPP_concept swappable_with = + common_reference_with, detail::as_cref_t> && + CPP_requires_ref(defs::swappable_with_, T, U); + + } // inline namespace defs + + namespace detail + { + template + CPP_concept boolean_testable_impl_ = convertible_to; + + template + CPP_requires(boolean_testable_frag_, + requires(T && t) // + ( + !(T&&) t, + concepts::requires_> + )); + + template + CPP_concept boolean_testable_ = + CPP_requires_ref(boolean_testable_frag_, T) && + boolean_testable_impl_; + + CPP_DIAGNOSTIC_PUSH + CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL + + template + CPP_requires(weakly_equality_comparable_with_frag_, + requires(detail::as_cref_t t, detail::as_cref_t u) // + ( + concepts::requires_>, + concepts::requires_>, + concepts::requires_>, + concepts::requires_> + )); + template + CPP_concept weakly_equality_comparable_with_ = + CPP_requires_ref(weakly_equality_comparable_with_frag_, T, U); + + template + CPP_requires(partially_ordered_with_frag_, + requires(detail::as_cref_t& t, detail::as_cref_t& u) // + ( + concepts::requires_>, + concepts::requires_ u)>>, + concepts::requires_>, + concepts::requires_= u)>>, + concepts::requires_>, + concepts::requires_ t)>>, + concepts::requires_>, + concepts::requires_= t)>> + )); + template + CPP_concept partially_ordered_with_ = + CPP_requires_ref(partially_ordered_with_frag_, T, U); + + CPP_DIAGNOSTIC_POP + } // namespace detail + + inline namespace defs + { + //////////////////////////////////////////////////////////////////////// + // Comparison concepts + //////////////////////////////////////////////////////////////////////// + + template + CPP_concept equality_comparable = + detail::weakly_equality_comparable_with_; + + CPP_template(typename T, typename U)( + concept (equality_comparable_with_)(T, U), + equality_comparable< + common_reference_t, detail::as_cref_t>> + ); + template + CPP_concept equality_comparable_with = + equality_comparable && + equality_comparable && + detail::weakly_equality_comparable_with_ && + common_reference_with, detail::as_cref_t> && + CPP_concept_ref(concepts::equality_comparable_with_, T, U); + + template + CPP_concept totally_ordered = + equality_comparable && + detail::partially_ordered_with_; + + CPP_template(typename T, typename U)( + concept (totally_ordered_with_)(T, U), + totally_ordered< + common_reference_t< + detail::as_cref_t, + detail::as_cref_t>> CPP_and + detail::partially_ordered_with_); + + template + CPP_concept totally_ordered_with = + totally_ordered && + totally_ordered && + equality_comparable_with && + CPP_concept_ref(concepts::totally_ordered_with_, T, U); + + //////////////////////////////////////////////////////////////////////// + // Object concepts + //////////////////////////////////////////////////////////////////////// + + template + CPP_concept destructible = + std::is_nothrow_destructible::value; + + template + CPP_concept constructible_from = + destructible && + META_IS_CONSTRUCTIBLE(T, Args...); + + template + CPP_concept default_constructible = + constructible_from; + + template + CPP_concept move_constructible = + constructible_from && + convertible_to; + + CPP_template(typename T)( + concept (copy_constructible_)(T), + constructible_from && + constructible_from && + constructible_from && + convertible_to && + convertible_to && + convertible_to); + template + CPP_concept copy_constructible = + move_constructible && + CPP_concept_ref(concepts::copy_constructible_, T); + + CPP_template(typename T)( + concept (move_assignable_)(T), + assignable_from + ); + template + CPP_concept movable = + std::is_object::value && + move_constructible && + CPP_concept_ref(concepts::move_assignable_, T) && + swappable; + + CPP_template(typename T)( + concept (copy_assignable_)(T), + assignable_from + ); + template + CPP_concept copyable = + copy_constructible && + movable && + CPP_concept_ref(concepts::copy_assignable_, T); + + template + CPP_concept semiregular = + copyable && + default_constructible; + // Axiom: copies are independent. See Fundamentals of Generic + // Programming http://www.stepanovpapers.com/DeSt98.pdf + + template + CPP_concept regular = + semiregular && + equality_comparable; + + } // inline namespace defs +} // namespace concepts + +#endif // RANGES_V3_UTILITY_CONCEPTS_HPP diff --git a/linux/include/concepts/swap.hpp b/linux/include/concepts/swap.hpp new file mode 100644 index 000000000..dd7086411 --- /dev/null +++ b/linux/include/concepts/swap.hpp @@ -0,0 +1,340 @@ +/// \file +// Concepts library +// +// Copyright Eric Niebler 2013-present +// +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// Project home: https://github.com/ericniebler/range-v3 + +#ifndef CPP_SWAP_HPP +#define CPP_SWAP_HPP + +#include +#include +#include +#include + +// Note: constexpr implies inline, to retain the same visibility +// C++14 constexpr functions are inline in C++11 +#if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304L) ||\ + (!defined(__cpp_constexpr) && __cplusplus >= 201402L) +#define CPP_CXX14_CONSTEXPR constexpr +#else +#define CPP_CXX14_CONSTEXPR inline +#endif + +#ifndef CPP_CXX_INLINE_VARIABLES +#ifdef __cpp_inline_variables // TODO: fix this if SD-6 picks another name +#define CPP_CXX_INLINE_VARIABLES __cpp_inline_variables +// TODO: remove once clang defines __cpp_inline_variables (or equivalent) +#elif defined(__clang__) && \ + (__clang_major__ > 3 || __clang_major__ == 3 && __clang_minor__ == 9) && \ + __cplusplus > 201402L +#define CPP_CXX_INLINE_VARIABLES 201606L +#else +#define CPP_CXX_INLINE_VARIABLES __cplusplus +#endif // __cpp_inline_variables +#endif // CPP_CXX_INLINE_VARIABLES + +#if defined(_MSC_VER) && !defined(__clang__) +#if _MSC_VER < 1926 +#define CPP_WORKAROUND_MSVC_895622 // Error when phase 1 name binding finds only deleted function +#endif // _MSC_VER < 1926 +#endif // MSVC + +#if CPP_CXX_INLINE_VARIABLES < 201606L +#define CPP_INLINE_VAR +#define CPP_INLINE_VARIABLE(type, name) \ + inline namespace \ + { \ + constexpr auto &name = ::concepts::detail::static_const::value; \ + } \ + /**/ +#else // CPP_CXX_INLINE_VARIABLES >= 201606L +#define CPP_INLINE_VAR inline +#define CPP_INLINE_VARIABLE(type, name) \ + inline constexpr type name{}; \ + /**/ +#endif // CPP_CXX_INLINE_VARIABLES + +#if CPP_CXX_INLINE_VARIABLES < 201606L +#define CPP_DEFINE_CPO(type, name) \ + inline namespace \ + { \ + constexpr auto &name = ::concepts::detail::static_const::value; \ + } \ + /**/ +#else // CPP_CXX_INLINE_VARIABLES >= 201606L +#define CPP_DEFINE_CPO(type, name) \ + inline namespace _ \ + { \ + inline constexpr type name{}; \ + } \ + /**/ +#endif // CPP_CXX_INLINE_VARIABLES + +#if defined(_MSC_VER) && !defined(__clang__) +#define CPP_DIAGNOSTIC_PUSH __pragma(warning(push)) +#define CPP_DIAGNOSTIC_POP __pragma(warning(pop)) +#define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME +#define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL +#define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT +#else // ^^^ defined(_MSC_VER) ^^^ / vvv !defined(_MSC_VER) vvv +#if defined(__GNUC__) || defined(__clang__) +#define CPP_PRAGMA(X) _Pragma(#X) +#define CPP_DIAGNOSTIC_PUSH CPP_PRAGMA(GCC diagnostic push) +#define CPP_DIAGNOSTIC_POP CPP_PRAGMA(GCC diagnostic pop) +#define CPP_DIAGNOSTIC_IGNORE_PRAGMAS \ + CPP_PRAGMA(GCC diagnostic ignored "-Wpragmas") +#define CPP_DIAGNOSTIC_IGNORE(X) \ + CPP_DIAGNOSTIC_IGNORE_PRAGMAS \ + CPP_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \ + CPP_PRAGMA(GCC diagnostic ignored X) +#define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME \ + CPP_DIAGNOSTIC_IGNORE("-Wunknown-warning-option") \ + CPP_DIAGNOSTIC_IGNORE("-Winit-list-lifetime") +#define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL CPP_DIAGNOSTIC_IGNORE("-Wfloat-equal") +#define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT CPP_DIAGNOSTIC_IGNORE("-Wc++2a-compat") +#else +#define CPP_DIAGNOSTIC_PUSH +#define CPP_DIAGNOSTIC_POP +#define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME +#define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL +#define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT +#endif +#endif // MSVC/Generic configuration switch + +namespace concepts +{ + /// \cond + namespace detail + { + template + CPP_INLINE_VAR constexpr bool is_movable_v = + std::is_object::value && + std::is_move_constructible::value && + std::is_move_assignable::value; + + template + struct static_const + { + static constexpr T const value {}; + }; + template + constexpr T const static_const::value; + } + /// \endcond + + template + struct is_swappable; + + template + struct is_nothrow_swappable; + + template + struct is_swappable_with; + + template + struct is_nothrow_swappable_with; + + template + CPP_CXX14_CONSTEXPR + meta::if_c< + std::is_move_constructible::value && + std::is_assignable::value, T> + exchange(T &t, U &&u) + noexcept( + std::is_nothrow_move_constructible::value && + std::is_nothrow_assignable::value) + { + T tmp((T &&) t); + t = (U &&) u; + CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME + return tmp; + } + + /// \cond + namespace adl_swap_detail + { + struct nope + {}; + + // Intentionally create an ambiguity with std::swap, which is + // (possibly) unconstrained. + template + nope swap(T &, T &) = delete; + + template + nope swap(T (&)[N], T (&)[N]) = delete; + +#ifdef CPP_WORKAROUND_MSVC_895622 + nope swap(); +#endif + + template + decltype(swap(std::declval(), std::declval())) try_adl_swap_(int); + + template + nope try_adl_swap_(long); + + template + CPP_INLINE_VAR constexpr bool is_adl_swappable_v = + !META_IS_SAME(decltype(adl_swap_detail::try_adl_swap_(42)), nope); + + struct swap_fn + { + // Dispatch to user-defined swap found via ADL: + template + CPP_CXX14_CONSTEXPR + meta::if_c> + operator()(T &&t, U &&u) const + noexcept(noexcept(swap((T &&) t, (U &&) u))) + { + swap((T &&) t, (U &&) u); + } + + // For intrinsically swappable (i.e., movable) types for which + // a swap overload cannot be found via ADL, swap by moving. + template + CPP_CXX14_CONSTEXPR + meta::if_c< + !is_adl_swappable_v && + detail::is_movable_v> + operator()(T &a, T &b) const + noexcept(noexcept(b = concepts::exchange(a, (T &&) b))) + { + b = concepts::exchange(a, (T &&) b); + } + + // For arrays of intrinsically swappable (i.e., movable) types + // for which a swap overload cannot be found via ADL, swap array + // elements by moving. + template + CPP_CXX14_CONSTEXPR + meta::if_c< + !is_adl_swappable_v && + is_swappable_with::value> + operator()(T (&t)[N], U (&u)[N]) const + noexcept(is_nothrow_swappable_with::value) + { + for(std::size_t i = 0; i < N; ++i) + (*this)(t[i], u[i]); + } + + // For rvalue pairs and tuples of swappable types, swap the + // members. This permits code like: + // ranges::swap(std::tie(a,b,c), std::tie(d,e,f)); + template + CPP_CXX14_CONSTEXPR + meta::if_c::value && is_swappable_with::value> + operator()(std::pair &&left, std::pair &&right) const + noexcept( + is_nothrow_swappable_with::value && + is_nothrow_swappable_with::value) + { + swap_fn()(static_cast &&>(left).first, + static_cast &&>(right).first); + swap_fn()(static_cast &&>(left).second, + static_cast &&>(right).second); + } + + template + CPP_CXX14_CONSTEXPR + meta::if_c::value...>::value> + operator()(std::tuple &&left, std::tuple &&right) const + noexcept(meta::and_c::value...>::value) + { + swap_fn::impl( + static_cast &&>(left), + static_cast &&>(right), + meta::make_index_sequence{}); + } + + private: + template + static constexpr int ignore_unused(Ts &&...) + { + return 0; + } + template + CPP_CXX14_CONSTEXPR + static void impl(T &&left, U &&right, meta::index_sequence) + { + (void) swap_fn::ignore_unused( + (swap_fn()(std::get(static_cast(left)), + std::get(static_cast(right))), 42)...); + } + }; + + template + struct is_swappable_with_ + : std::false_type + {}; + + template + struct is_swappable_with_(), std::declval())), + decltype(swap_fn()(std::declval(), std::declval()))>> + : std::true_type + {}; + + template + struct is_nothrow_swappable_with_ + : meta::bool_(), std::declval())) && + noexcept(swap_fn()(std::declval(), std::declval()))> + {}; + + // Q: Should std::reference_wrapper be considered a proxy wrt swapping rvalues? + // A: No. Its operator= is currently defined to reseat the references, so + // std::swap(ra, rb) already means something when ra and rb are (lvalue) + // reference_wrappers. That reseats the reference wrappers but leaves the + // referents unmodified. Treating rvalue reference_wrappers differently would + // be confusing. + + // Q: Then why is it OK to "re"-define swap for pairs and tuples of references? + // A: Because as defined above, swapping an rvalue tuple of references has the same + // semantics as swapping an lvalue tuple of references. Rather than reseat the + // references, assignment happens *through* the references. + + // Q: But I have an iterator whose operator* returns an rvalue + // std::reference_wrapper. How do I make it model indirectly_swappable? + // A: With an overload of iter_swap. + } + /// \endcond + + /// \ingroup group-utility + template + struct is_swappable_with + : adl_swap_detail::is_swappable_with_ + {}; + + /// \ingroup group-utility + template + struct is_nothrow_swappable_with + : meta::and_< + is_swappable_with, + adl_swap_detail::is_nothrow_swappable_with_> + {}; + + /// \ingroup group-utility + template + struct is_swappable + : is_swappable_with + {}; + + /// \ingroup group-utility + template + struct is_nothrow_swappable + : is_nothrow_swappable_with + {}; + + /// \ingroup group-utility + /// \relates adl_swap_detail::swap_fn + CPP_DEFINE_CPO(adl_swap_detail::swap_fn, swap) +} + +#endif diff --git a/linux/include/concepts/type_traits.hpp b/linux/include/concepts/type_traits.hpp new file mode 100644 index 000000000..f8ee95c9c --- /dev/null +++ b/linux/include/concepts/type_traits.hpp @@ -0,0 +1,379 @@ +/// \file +// Concepts library +// +// Copyright Eric Niebler 2013-present +// +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// Project home: https://github.com/ericniebler/range-v3 + +#ifndef CPP_TYPE_TRAITS_HPP +#define CPP_TYPE_TRAITS_HPP + +#include +#include +#include +#include + +namespace concepts +{ + template + using remove_cvref_t = + typename std::remove_cv< + typename std::remove_reference::type>::type; + + /// \cond + namespace detail + { + template + using is_convertible = std::is_convertible>, To>; + + template + struct if_else_ + { + template + using invoke = U; + }; + template<> + struct if_else_ + { + template + using invoke = T; + }; + template + using if_else_t = meta::invoke, T, U>; + + template + struct if_ + {}; + template<> + struct if_ + { + template + using invoke = T; + }; + template + using if_t = meta::invoke, T>; + + template + struct _copy_cv_ + { + using type = To; + }; + template + struct _copy_cv_ + { + using type = To const; + }; + template + struct _copy_cv_ + { + using type = To volatile; + }; + template + struct _copy_cv_ + { + using type = To const volatile; + }; + template + using _copy_cv = meta::_t<_copy_cv_>; + + //////////////////////////////////////////////////////////////////////////////////////// + template + struct _builtin_common; + + template + using _builtin_common_t = meta::_t<_builtin_common>; + + template + using _cond_res = decltype(true ? std::declval() : std::declval()); + + template> + using _rref_res = + if_else_t::value, meta::_t> &&, R>; + + template + using _lref_res = _cond_res<_copy_cv &, _copy_cv &>; + + template + struct as_cref_ + { + using type = T const &; + }; + template + struct as_cref_ + { + using type = T const &; + }; + template + struct as_cref_ + { + using type = T const &; + }; + template<> + struct as_cref_ + { + using type = void; + }; + template<> + struct as_cref_ + { + using type = void const; + }; + + template + using as_cref_t = typename as_cref_::type; + + template + using decay_t = typename std::decay::type; + + #if !defined(__GNUC__) || defined(__clang__) + template + struct _builtin_common_3 + {}; + template + struct _builtin_common_3, as_cref_t>>> + : std::decay<_cond_res, as_cref_t>> + {}; + template + struct _builtin_common_2 + : _builtin_common_3 + {}; + template + struct _builtin_common_2>> + : std::decay<_cond_res> + {}; + template + struct _builtin_common + : _builtin_common_2 + {}; + template + struct _builtin_common>::value && + is_convertible>::value>> + { + using type = _rref_res; + }; + template + struct _builtin_common + : meta::defer<_lref_res, T, U> + {}; + template + struct _builtin_common>::value>> + : _builtin_common + {}; + template + struct _builtin_common + : _builtin_common + {}; + #else + template + struct _builtin_common_3 + {}; + template + struct _builtin_common_3, as_cref_t>>> + : std::decay<_cond_res, as_cref_t>> + {}; + template + struct _builtin_common_2 + : _builtin_common_3 + {}; + template + struct _builtin_common_2>> + : std::decay<_cond_res> + {}; + template + struct _builtin_common + : _builtin_common_2 + {}; + template + struct _builtin_common_rr + : _builtin_common_2 + {}; + template + struct _builtin_common_rr>::value && + is_convertible>::value>> + { + using type = _rref_res; + }; + template + struct _builtin_common + : _builtin_common_rr + {}; + template + struct _builtin_common + : meta::defer<_lref_res, T, U> + {}; + template + struct _builtin_common_lr + : _builtin_common_2 + {}; + template + struct _builtin_common_lr>::value>> + : _builtin_common + {}; + template + struct _builtin_common + : _builtin_common_lr + {}; + template + struct _builtin_common + : _builtin_common + {}; + #endif + } + /// \endcond + + /// \addtogroup group-utility Utility + /// @{ + /// + + /// Users should specialize this to hook the \c common_with concept + /// until \c std gets a SFINAE-friendly \c std::common_type and there's + /// some sane way to deal with cv and ref qualifiers. + template + struct common_type + {}; + + template + struct common_type + : std::decay + {}; + + template + struct common_type + : detail::if_else_t< + (META_IS_SAME(detail::decay_t, T) && + META_IS_SAME(detail::decay_t, U) ), + meta::defer, + common_type, detail::decay_t>> + {}; + + template + using common_type_t = typename common_type::type; + + template + struct common_type + : meta::lazy::fold, T, meta::quote> + {}; + + /// @} + + /// \addtogroup group-utility Utility + /// @{ + /// + + /// Users can specialize this to hook the \c common_reference_with concept. + /// \sa `common_reference` + template< + typename T, + typename U, + template class TQual, + template class UQual> + struct basic_common_reference + {}; + + /// \cond + namespace detail + { + using _rref = + meta::quote_trait; + using _lref = + meta::quote_trait; + + template + struct _xref + { + template + using invoke = T; + }; + template + struct _xref + { + template + using invoke = + meta::_t, U>>>; + }; + template + struct _xref + { + template + using invoke = + meta::_t, U>>>; + }; + template + struct _xref + { + template + using invoke = U const; + }; + template + struct _xref + { + template + using invoke = U volatile; + }; + template + struct _xref + { + template + using invoke = U const volatile; + }; + + template + using _basic_common_reference = + basic_common_reference< + remove_cvref_t, + remove_cvref_t, + _xref::template invoke, + _xref::template invoke>; + + template + struct _common_reference2 + : if_else_t< + meta::is_trait<_basic_common_reference>::value, + _basic_common_reference, + common_type> + {}; + + template + struct _common_reference2>::value>> + : _builtin_common + {}; + } + /// \endcond + + /// Users can specialize this to hook the \c common_reference_with concept. + /// \sa `basic_common_reference` + template + struct common_reference + {}; + + template + struct common_reference + { + using type = T; + }; + + template + struct common_reference + : detail::_common_reference2 + {}; + + template + using common_reference_t = typename common_reference::type; + + template + struct common_reference + : meta::lazy::fold, T, meta::quote> + {}; + /// @} +} // namespace concepts + +#endif diff --git a/linux/include/meta/meta.hpp b/linux/include/meta/meta.hpp new file mode 100644 index 000000000..c87e103f8 --- /dev/null +++ b/linux/include/meta/meta.hpp @@ -0,0 +1,3973 @@ +/// \file meta.hpp Tiny meta-programming library. +// +// Meta library +// +// Copyright Eric Niebler 2014-present +// +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// Project home: https://github.com/ericniebler/meta +// + +#ifndef META_HPP +#define META_HPP + +#include +#include +#include +#include +#include + +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wdocumentation-deprecated-sync" +#pragma GCC diagnostic ignored "-Wmissing-variable-declarations" +#endif + +/// \defgroup meta Meta +/// +/// A tiny metaprogramming library + +/// \defgroup trait Trait +/// Trait invocation/composition. +/// \ingroup meta + +/// \defgroup invocation Invocation +/// Trait invocation +/// \ingroup trait + +/// \defgroup composition Composition +/// Trait composition +/// \ingroup trait + +/// \defgroup logical Logical +/// Logical operations +/// \ingroup meta + +/// \defgroup algorithm Algorithms +/// Algorithms. +/// \ingroup meta + +/// \defgroup query Query/Search +/// Query and search algorithms +/// \ingroup algorithm + +/// \defgroup transformation Transformation +/// Transformation algorithms +/// \ingroup algorithm + +/// \defgroup runtime Runtime +/// Runtime algorithms +/// \ingroup algorithm + +/// \defgroup datatype Datatype +/// Datatypes. +/// \ingroup meta + +/// \defgroup list list_like +/// \ingroup datatype + +/// \defgroup integral Integer sequence +/// Equivalent to C++14's `std::integer_sequence` +/// \ingroup datatype + +/// \defgroup extension Extension +/// Extend meta with your own datatypes. +/// \ingroup datatype + +/// \defgroup math Math +/// Integral constant arithmetic. +/// \ingroup meta + +/// \defgroup lazy_trait lazy +/// \ingroup trait + +/// \defgroup lazy_invocation lazy +/// \ingroup invocation + +/// \defgroup lazy_composition lazy +/// \ingroup composition + +/// \defgroup lazy_logical lazy +/// \ingroup logical + +/// \defgroup lazy_query lazy +/// \ingroup query + +/// \defgroup lazy_transformation lazy +/// \ingroup transformation + +/// \defgroup lazy_list lazy +/// \ingroup list + +/// \defgroup lazy_datatype lazy +/// \ingroup datatype + +/// \defgroup lazy_math lazy +/// \ingroup math + +/// Tiny metaprogramming library +namespace meta +{ + namespace detail + { + /// Returns a \p T nullptr + template + constexpr T *_nullptr_v() + { + return nullptr; + } + +#if META_CXX_VARIABLE_TEMPLATES + template + META_INLINE_VAR constexpr T *nullptr_v = nullptr; +#endif + } // namespace detail + + /// An empty type. + /// \ingroup datatype + struct nil_ + { + }; + + /// Type alias for \p T::type. + /// \ingroup invocation + template + using _t = typename T::type; + +#if META_CXX_VARIABLE_TEMPLATES || defined(META_DOXYGEN_INVOKED) + /// Variable alias for \c T::type::value + /// \note Requires C++14 or greater. + /// \ingroup invocation + template + constexpr typename T::type::value_type _v = T::type::value; +#endif + + /// Lazy versions of meta actions + namespace lazy + { + /// \sa `meta::_t` + /// \ingroup lazy_invocation + template + using _t = defer<_t, T>; + } // namespace lazy + + /// An integral constant wrapper for \c std::size_t. + /// \ingroup integral + template + using size_t = std::integral_constant; + + /// An integral constant wrapper for \c bool. + /// \ingroup integral + template + using bool_ = std::integral_constant; + + /// An integral constant wrapper for \c int. + /// \ingroup integral + template + using int_ = std::integral_constant; + + /// An integral constant wrapper for \c char. + /// \ingroup integral + template + using char_ = std::integral_constant; + + /////////////////////////////////////////////////////////////////////////////////////////// + // Math operations + /// An integral constant wrapper around the result of incrementing the wrapped integer \c + /// T::type::value. + template + using inc = std::integral_constant; + + /// An integral constant wrapper around the result of decrementing the wrapped integer \c + /// T::type::value. + template + using dec = std::integral_constant; + + /// An integral constant wrapper around the result of adding the two wrapped integers + /// \c T::type::value and \c U::type::value. + /// \ingroup math + template + using plus = std::integral_constant; + + /// An integral constant wrapper around the result of subtracting the two wrapped integers + /// \c T::type::value and \c U::type::value. + /// \ingroup math + template + using minus = std::integral_constant; + + /// An integral constant wrapper around the result of multiplying the two wrapped integers + /// \c T::type::value and \c U::type::value. + /// \ingroup math + template + using multiplies = std::integral_constant; + + /// An integral constant wrapper around the result of dividing the two wrapped integers \c + /// T::type::value and \c U::type::value. + /// \ingroup math + template + using divides = std::integral_constant; + + /// An integral constant wrapper around the result of negating the wrapped integer + /// \c T::type::value. + /// \ingroup math + template + using negate = std::integral_constant; + + /// An integral constant wrapper around the remainder of dividing the two wrapped integers + /// \c T::type::value and \c U::type::value. + /// \ingroup math + template + using modulus = std::integral_constant; + + /// A Boolean integral constant wrapper around the result of comparing \c T::type::value and + /// \c U::type::value for equality. + /// \ingroup math + template + using equal_to = bool_; + + /// A Boolean integral constant wrapper around the result of comparing \c T::type::value and + /// \c U::type::value for inequality. + /// \ingroup math + template + using not_equal_to = bool_; + + /// A Boolean integral constant wrapper around \c true if \c T::type::value is greater than + /// \c U::type::value; \c false, otherwise. + /// \ingroup math + template + using greater = bool_<(T::type::value > U::type::value)>; + + /// A Boolean integral constant wrapper around \c true if \c T::type::value is less than \c + /// U::type::value; \c false, otherwise. + /// \ingroup math + template + using less = bool_<(T::type::value < U::type::value)>; + + /// A Boolean integral constant wrapper around \c true if \c T::type::value is greater than + /// or equal to \c U::type::value; \c false, otherwise. + /// \ingroup math + template + using greater_equal = bool_<(T::type::value >= U::type::value)>; + + /// A Boolean integral constant wrapper around \c true if \c T::type::value is less than or + /// equal to \c U::type::value; \c false, otherwise. + /// \ingroup math + template + using less_equal = bool_<(T::type::value <= U::type::value)>; + + /// An integral constant wrapper around the result of bitwise-and'ing the two wrapped + /// integers \c T::type::value and \c U::type::value. + /// \ingroup math + template + using bit_and = std::integral_constant; + + /// An integral constant wrapper around the result of bitwise-or'ing the two wrapped + /// integers \c T::type::value and \c U::type::value. + /// \ingroup math + template + using bit_or = std::integral_constant; + + /// An integral constant wrapper around the result of bitwise-exclusive-or'ing the two + /// wrapped integers \c T::type::value and \c U::type::value. + /// \ingroup math + template + using bit_xor = std::integral_constant; + + /// An integral constant wrapper around the result of bitwise-complementing the wrapped + /// integer \c T::type::value. + /// \ingroup math + template + using bit_not = std::integral_constant; + + namespace lazy + { + /// \sa 'meta::int' + /// \ingroup lazy_math + template + using inc = defer; + + /// \sa 'meta::dec' + /// \ingroup lazy_math + template + using dec = defer; + + /// \sa 'meta::plus' + /// \ingroup lazy_math + template + using plus = defer; + + /// \sa 'meta::minus' + /// \ingroup lazy_math + template + using minus = defer; + + /// \sa 'meta::multiplies' + /// \ingroup lazy_math + template + using multiplies = defer; + + /// \sa 'meta::divides' + /// \ingroup lazy_math + template + using divides = defer; + + /// \sa 'meta::negate' + /// \ingroup lazy_math + template + using negate = defer; + + /// \sa 'meta::modulus' + /// \ingroup lazy_math + template + using modulus = defer; + + /// \sa 'meta::equal_to' + /// \ingroup lazy_math + template + using equal_to = defer; + + /// \sa 'meta::not_equal_t' + /// \ingroup lazy_math + template + using not_equal_to = defer; + + /// \sa 'meta::greater' + /// \ingroup lazy_math + template + using greater = defer; + + /// \sa 'meta::less' + /// \ingroup lazy_math + template + using less = defer; + + /// \sa 'meta::greater_equal' + /// \ingroup lazy_math + template + using greater_equal = defer; + + /// \sa 'meta::less_equal' + /// \ingroup lazy_math + template + using less_equal = defer; + + /// \sa 'meta::bit_and' + /// \ingroup lazy_math + template + using bit_and = defer; + + /// \sa 'meta::bit_or' + /// \ingroup lazy_math + template + using bit_or = defer; + + /// \sa 'meta::bit_xor' + /// \ingroup lazy_math + template + using bit_xor = defer; + + /// \sa 'meta::bit_not' + /// \ingroup lazy_math + template + using bit_not = defer; + } // namespace lazy + + /// \cond + namespace detail + { + enum class indices_strategy_ + { + done, + repeat, + recurse + }; + + constexpr indices_strategy_ strategy_(std::size_t cur, std::size_t end) + { + return cur >= end ? indices_strategy_::done + : cur * 2 <= end ? indices_strategy_::repeat + : indices_strategy_::recurse; + } + + template + constexpr std::size_t range_distance_(T begin, T end) + { + return begin <= end ? static_cast(end - begin) + : throw "The start of the integer_sequence must not be " + "greater than the end"; + } + + template + struct make_indices_ + { + using type = State; + }; + + template + struct coerce_indices_ + { + }; + } // namespace detail + /// \endcond + + /////////////////////////////////////////////////////////////////////////////////////////// + // integer_sequence +#if !META_CXX_INTEGER_SEQUENCE + /// A container for a sequence of compile-time integer constants. + /// \ingroup integral + template + struct integer_sequence + { + using value_type = T; + /// \return `sizeof...(Is)` + static constexpr std::size_t size() noexcept { return sizeof...(Is); } + }; +#endif + + /////////////////////////////////////////////////////////////////////////////////////////// + // index_sequence + /// A container for a sequence of compile-time integer constants of type + /// \c std::size_t + /// \ingroup integral + template + using index_sequence = integer_sequence; + +#if META_HAS_MAKE_INTEGER_SEQ && !defined(META_DOXYGEN_INVOKED) + // Implement make_integer_sequence and make_index_sequence with the + // __make_integer_seq builtin on compilers that provide it. (Redirect + // through decltype to workaround suspected clang bug.) + /// \cond + namespace detail + { + template + __make_integer_seq make_integer_sequence_(); + } + /// \endcond + + template + using make_integer_sequence = decltype(detail::make_integer_sequence_()); + + template + using make_index_sequence = make_integer_sequence; +#else + /// Generate \c index_sequence containing integer constants [0,1,2,...,N-1]. + /// \par Complexity + /// \f$ O(log(N)) \f$. + /// \ingroup integral + template + using make_index_sequence = + _t, detail::strategy_(1, N)>>; + + /// Generate \c integer_sequence containing integer constants [0,1,2,...,N-1]. + /// \par Complexity + /// \f$ O(log(N)) \f$. + /// \ingroup integral + template + using make_integer_sequence = + _t(N)>>>; +#endif + + /////////////////////////////////////////////////////////////////////////////////////////// + // integer_range + /// Makes the integer sequence [From, To). + /// \par Complexity + /// \f$ O(log(To - From)) \f$. + /// \ingroup integral + template + using integer_range = + _t>>; + + /// \cond + namespace detail + { + template + struct concat_indices_ + { + }; + + template + struct concat_indices_, index_sequence> + { + using type = index_sequence; + }; + + template <> + struct make_indices_<0u, index_sequence<0>, indices_strategy_::done> + { + using type = index_sequence<>; + }; + + template + struct make_indices_, indices_strategy_::repeat> + : make_indices_, + detail::strategy_(sizeof...(Values) * 2, End)> + { + }; + + template + struct make_indices_, indices_strategy_::recurse> + : concat_indices_, + make_index_sequence> + { + }; + + template + struct coerce_indices_> + { + using type = + integer_sequence(static_cast(Values) + Offset)...>; + }; + } // namespace detail + /// \endcond + + /// Evaluate the invocable \p Fn with the arguments \p Args. + /// \ingroup invocation + template + using invoke = typename Fn::template invoke; + + /// Lazy versions of meta actions + namespace lazy + { + /// \sa `meta::invoke` + /// \ingroup lazy_invocation + template + using invoke = defer; + } // namespace lazy + + /// A trait that always returns its argument \p T. It is also an invocable + /// that always returns \p T. + /// \ingroup trait + /// \ingroup invocation + template + struct id + { +#if defined(META_WORKAROUND_CWG_1558) && !defined(META_DOXYGEN_INVOKED) + // Redirect through decltype for compilers that have not + // yet implemented CWG 1558: + static id impl(void *); + + template + using invoke = _t *>(nullptr)))>; +#else + template + using invoke = T; +#endif + + using type = T; + }; + + /// An alias for type \p T. Useful in non-deduced contexts. + /// \ingroup trait + template + using id_t = _t>; + + namespace lazy + { + /// \sa `meta::id` + /// \ingroup lazy_trait + /// \ingroup lazy_invocation + template + using id = defer; + } // namespace lazy + + /// An alias for `void`. + /// \ingroup trait +#if defined(META_WORKAROUND_CWG_1558) && !defined(META_DOXYGEN_INVOKED) + // Redirect through decltype for compilers that have not + // yet implemented CWG 1558: + template + using void_ = invoke, Ts...>; +#else + template + using void_ = void; +#endif + +#if META_CXX_VARIABLE_TEMPLATES +#ifdef META_CONCEPT + /// `true` if `T::type` exists and names a type; `false` otherwise. + /// \ingroup trait + template + META_INLINE_VAR constexpr bool is_trait_v = trait; + + /// `true` if `T::invoke` exists and names a class template; `false` otherwise. + /// \ingroup trait + template + META_INLINE_VAR constexpr bool is_callable_v = invocable; +#else // ^^^ Concepts / No concepts vvv + /// \cond + namespace detail + { + template + META_INLINE_VAR constexpr bool is_trait_ = false; + + template + META_INLINE_VAR constexpr bool is_trait_> = true; + + template + META_INLINE_VAR constexpr bool is_callable_ = false; + + template + META_INLINE_VAR constexpr bool is_callable_>> = true; + } // namespace detail + /// \endcond + + /// `true` if `T::type` exists and names a type; `false` otherwise. + /// \ingroup trait + template + META_INLINE_VAR constexpr bool is_trait_v = detail::is_trait_; + + /// `true` if `T::invoke` exists and names a class template; `false` otherwise. + /// \ingroup trait + template + META_INLINE_VAR constexpr bool is_callable_v = detail::is_callable_; +#endif // Concepts vs. variable templates + + /// An alias for `std::true_type` if `T::type` exists and names a type; otherwise, it's an + /// alias for `std::false_type`. + /// \ingroup trait + template + using is_trait = bool_>; + + /// An alias for `std::true_type` if `T::invoke` exists and names a class template; + /// otherwise, it's an alias for `std::false_type`. + /// \ingroup trait + template + using is_callable = bool_>; +#else // ^^^ META_CXX_VARIABLE_TEMPLATES / !META_CXX_VARIABLE_TEMPLATES vvv + /// \cond + namespace detail + { + template + struct is_trait_ + { + using type = std::false_type; + }; + + template + struct is_trait_> + { + using type = std::true_type; + }; + + template + struct is_callable_ + { + using type = std::false_type; + }; + + template + struct is_callable_>> + { + using type = std::true_type; + }; + } // namespace detail + /// \endcond + + template + using is_trait = _t>; + + /// An alias for `std::true_type` if `T::invoke` exists and names a class + /// template or alias template; otherwise, it's an alias for + /// `std::false_type`. + /// \ingroup trait + template + using is_callable = _t>; +#endif + + /// \cond + namespace detail + { +#ifdef META_CONCEPT + template