diff --git a/libs/array/test/array.cpp b/libs/array/test/array.cpp index afb17483..0d14b7e0 100644 --- a/libs/array/test/array.cpp +++ b/libs/array/test/array.cpp @@ -90,17 +90,19 @@ namespace testspr { } // assign + TESTSPR_BOTH_ASSERT(testspr::equal(arr1.assign(-1), array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); { auto arr = arr1; arr.assign(-1); - TESTSPR_ASSERT(arr[0] == -1); + TESTSPR_ASSERT(testspr::equal(arr, array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); } // fill + TESTSPR_BOTH_ASSERT(testspr::equal(arr1.fill(-1), array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); { auto arr = arr1; arr.fill(-1); - TESTSPR_ASSERT(arr[0] == -1); + TESTSPR_ASSERT(testspr::equal(arr, array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); } // swap diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index bdb13afe..9aeb73ff 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -17,6 +17,19 @@ #endif namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR T const& + array_dummy_get(T const& value) { + return value; + } + template + inline SPROUT_CONSTEXPR Array + array_fill_impl(T const& value, sprout::index_tuple) { + return Array{{array_dummy_get(value)...}}; + } + } // namespace detail + // // array // @@ -47,6 +60,9 @@ namespace sprout { void fill(const_reference value) { std::fill_n(begin(), size(), value); } + SPROUT_CONSTEXPR array fill(const_reference value) const { + return sprout::detail::array_fill_impl(value, sprout::index_n<0, N>::make()); + } void swap(array& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { std::swap_ranges(other.begin(), other.end(), begin()); } @@ -176,6 +192,9 @@ namespace sprout { void assign(const_reference value) { fill(value); } + SPROUT_CONSTEXPR array assign(const_reference value) const { + return fill(value); + } void rangecheck(size_type i) const { if (i >= size()) { throw std::out_of_range("array<>: index out of range"); @@ -189,17 +208,16 @@ namespace sprout { // swap // template - inline void swap(sprout::array& lhs, sprout::array& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + inline void swap(sprout::array& lhs, sprout::array& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { lhs.swap(rhs); } namespace detail { template - inline SPROUT_CONSTEXPR sprout::array to_array_impl( - T const (& arr)[N], - sprout::index_tuple - ) - { + inline SPROUT_CONSTEXPR sprout::array + to_array_impl(T const (& arr)[N], sprout::index_tuple) { return sprout::array{{arr[Indexes]...}}; } } // namespace detail @@ -207,7 +225,8 @@ namespace sprout { // to_array // template - inline SPROUT_CONSTEXPR sprout::array to_array(T const (& arr)[N]) { + inline SPROUT_CONSTEXPR sprout::array + to_array(T const (& arr)[N]) { return sprout::detail::to_array_impl(arr, sprout::index_range<0, N>::make()); } } // namespace sprout diff --git a/sprout/array/hash.hpp b/sprout/array/hash.hpp index c81f620c..0abd56f9 100644 --- a/sprout/array/hash.hpp +++ b/sprout/array/hash.hpp @@ -8,7 +8,8 @@ namespace sprout { template - inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::array const& v) { + inline SPROUT_CONSTEXPR std::size_t + hash_value(sprout::array const& v) { return sprout::hash_range(v.begin(), v.end()); } } // namespace sprout diff --git a/sprout/array/make_array.hpp b/sprout/array/make_array.hpp index c990b4f3..46b6c128 100644 --- a/sprout/array/make_array.hpp +++ b/sprout/array/make_array.hpp @@ -13,7 +13,8 @@ namespace sprout { // make_array // template - inline SPROUT_CONSTEXPR sprout::array make_array(Types&&... args) { + inline SPROUT_CONSTEXPR sprout::array + make_array(Types&&... args) { return sprout::array{{sprout::forward(args)...}}; } @@ -24,11 +25,13 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::array< typename std::decay::type...>::type>::type, sizeof...(Types) - > make_common_array(Types&&... args) { - return sprout::array< + > + make_common_array(Types&&... args) { + typedef sprout::array< typename std::decay::type...>::type>::type, sizeof...(Types) - >{{sprout::forward(args)...}}; + > type; + return type{{sprout::forward(args)...}}; } } // namespace sprout diff --git a/sprout/array/tuple.hpp b/sprout/array/tuple.hpp index 0feaaed0..96405cdb 100644 --- a/sprout/array/tuple.hpp +++ b/sprout/array/tuple.hpp @@ -4,11 +4,12 @@ #include #include #include +#include #include #include #include -namespace sprout { +namespace sprout_adl { // // tuple_get // @@ -29,7 +30,7 @@ namespace sprout { tuple_get(sprout::array&& t) SPROUT_NOEXCEPT { return sprout::move(sprout::tuples::get(t)); } -} // namespace sprout +} // namespace sprout_adl namespace std { // diff --git a/sprout/type_traits/has_xxx.hpp b/sprout/type_traits/has_xxx.hpp index bcfabc63..7df75581 100644 --- a/sprout/type_traits/has_xxx.hpp +++ b/sprout/type_traits/has_xxx.hpp @@ -7,6 +7,7 @@ // // SPROUT_HAS_XXX_TYPE_DEF +// SPROUT_HAS_XXX_TYPE_DEF_LAZY // #define SPROUT_HAS_XXX_TYPE_DEF(NAME, TYPE) \ template \ @@ -17,15 +18,12 @@ struct NAME \ : decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)(0)) \ {} - -// -// SPROUT_HAS_XXX_TYPE_DEF_LAZY -// #define SPROUT_HAS_XXX_TYPE_DEF_LAZY(TYPE) \ SPROUT_HAS_XXX_TYPE_DEF(SPROUT_PP_CAT(has_, TYPE), TYPE) // // SPROUT_HAS_XXX_VALUE_DEF +// SPROUT_HAS_XXX_VALUE_DEF_LAZY // #define SPROUT_HAS_XXX_VALUE_DEF(NAME, VALUE) \ template \ @@ -36,10 +34,6 @@ struct NAME \ : decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_value_, VALUE), __LINE__)(0)) \ {} - -// -// SPROUT_HAS_XXX_VALUE_DEF_LAZY -// #define SPROUT_HAS_XXX_VALUE_DEF_LAZY(VALUE) \ SPROUT_HAS_XXX_VALUE_DEF(SPROUT_PP_CAT(has_, VALUE), VALUE) diff --git a/sprout/variant.hpp b/sprout/variant.hpp index 754eccf5..1640face 100644 --- a/sprout/variant.hpp +++ b/sprout/variant.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/sprout/variant/get.hpp b/sprout/variant/get.hpp index 88216f10..0731da4d 100644 --- a/sprout/variant/get.hpp +++ b/sprout/variant/get.hpp @@ -11,35 +11,15 @@ namespace sprout { // get // template - inline SPROUT_CONSTEXPR U const& get(sprout::variant const& operand) { + inline SPROUT_CONSTEXPR U const& + get(sprout::variant const& operand) { return operand.template get(); } template - inline SPROUT_CONSTEXPR U& get(sprout::variant& operand) { + inline SPROUT_CONSTEXPR U& + get(sprout::variant& operand) { return operand.template get(); } } // namespace sprout -namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element< - I, - sprout::variant - >::type const& - tuple_get(sprout::variant const& operand) { - return operand.template get_at(); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element< - I, - sprout::variant - >::type& - tuple_get(sprout::variant& operand) { - return operand.template get_at(); - } -} // namespace sprout_adl - #endif // #ifndef SPROUT_VARIANT_GET_HPP diff --git a/sprout/variant/tuple.hpp b/sprout/variant/tuple.hpp new file mode 100644 index 00000000..f0abe6b7 --- /dev/null +++ b/sprout/variant/tuple.hpp @@ -0,0 +1,59 @@ +#ifndef SPROUT_VARIANT_TUPLE_HPP +#define SPROUT_VARIANT_TUPLE_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout_adl { + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element< + I, + sprout::variant + >::type const& + tuple_get(sprout::variant const& t) { + return t.template get_at(); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element< + I, + sprout::variant + >::type& + tuple_get(sprout::variant& t) { + return t.template get_at(); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element< + I, + sprout::variant + >::type&& + tuple_get(sprout::variant&& t) { + return sprout::move(sprout::tuples::get(t)); + } +} // namespace sprout_adl + +namespace std { + // + // tuple_size + // + template + struct tuple_size > + : public std::tuple_size::tuple_type> + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public std::tuple_element::tuple_type> + {}; +} // namespace std + +#endif // #ifndef SPROUT_VARIANT_TUPLE_HPP diff --git a/sprout/variant/variant.hpp b/sprout/variant/variant.hpp index ea335353..3155883c 100644 --- a/sprout/variant/variant.hpp +++ b/sprout/variant/variant.hpp @@ -252,31 +252,11 @@ namespace sprout { // swap // template - inline void swap( - sprout::variant& lhs, - sprout::variant& rhs - ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + inline void swap(sprout::variant& lhs, sprout::variant& rhs) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { lhs.swap(rhs); } } // namespace sprout -namespace std { - // - // tuple_size - // - template - struct tuple_size > - : public std::tuple_size::tuple_type> - {}; - - // - // tuple_element - // - template - struct tuple_element > - : public std::tuple_element::tuple_type> - {}; -} // namespace std - #endif // #ifndef SPROUT_VARIANT_VARIANT_HPP