diff --git a/libs/array/test/array.cpp b/libs/array/test/array.cpp index 0d14b7e0..f3099f80 100644 --- a/libs/array/test/array.cpp +++ b/libs/array/test/array.cpp @@ -90,33 +90,33 @@ namespace testspr { } // assign - TESTSPR_BOTH_ASSERT(testspr::equal(arr1.assign(-1), array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); + TESTSPR_BOTH_ASSERT(testspr::equal(arr1.assign(-1), sprout::array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); { auto arr = arr1; arr.assign(-1); - TESTSPR_ASSERT(testspr::equal(arr, array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); + TESTSPR_ASSERT(testspr::equal(arr, sprout::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}})); + TESTSPR_BOTH_ASSERT(testspr::equal(arr1.fill(-1), sprout::array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); { auto arr = arr1; arr.fill(-1); - TESTSPR_ASSERT(testspr::equal(arr, array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); + TESTSPR_ASSERT(testspr::equal(arr, sprout::array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}})); } // swap { - auto arr1 = array{{1, 2}}; - auto arr2 = array{{-1, -2}}; + auto arr1 = sprout::array{{1, 2}}; + auto arr2 = sprout::array{{-1, -2}}; arr1.swap(arr2); TESTSPR_ASSERT(arr1[0] == -1); } // operator= { - auto arr1 = array{{1, 2}}; - arr1 = array{{-1, -2}}; + auto arr1 = sprout::array{{1, 2}}; + arr1 = sprout::array{{-1, -2}}; TESTSPR_ASSERT(arr1[0] == -1); } @@ -137,6 +137,30 @@ namespace testspr { // operator>= TESTSPR_BOTH_ASSERT(arr1 >= arr2); + + // get + TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(arr1) == 1); + TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(arr1) == 2); + { + auto arr4 = arr1; + TESTSPR_ASSERT(sprout::tuples::get<0>(arr4) == 1); + TESTSPR_ASSERT(sprout::tuples::get<1>(arr4) == 2); + } + + // tuple_size + TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 10); + + // tuple_element + TESTSPR_BOTH_ASSERT((std::is_same::type, int const>::value)); + TESTSPR_BOTH_ASSERT((std::is_same::type, int const>::value)); + + // is_array + TESTSPR_BOTH_ASSERT(sprout::is_array::value); + TESTSPR_BOTH_ASSERT(!sprout::is_array::value); + + // sprout::to_hash, sprout::hash + TESTSPR_BOTH_ASSERT(sprout::to_hash(arr1) == sprout::hash()(arr1)); + TESTSPR_BOTH_ASSERT(sprout::to_hash(arr1) != sprout::to_hash(sprout::array{{}})); } } } // namespace testspr diff --git a/libs/bitset/test/bitset.cpp b/libs/bitset/test/bitset.cpp index 18750244..75b5546d 100644 --- a/libs/bitset/test/bitset.cpp +++ b/libs/bitset/test/bitset.cpp @@ -196,7 +196,8 @@ namespace testspr { // 20.5.3 hash support // sprout::to_hash, sprout::hash - TESTSPR_BOTH_ASSERT(sprout::to_hash(bits1) == sprout::hash()(bits1)); + TESTSPR_BOTH_ASSERT(sprout::to_hash(bits1) == sprout::hash()(bits1)); + TESTSPR_BOTH_ASSERT(sprout::to_hash(bits1) != sprout::to_hash(bitset_t())); } } } // namespace testspr diff --git a/libs/optional/test/optional.cpp b/libs/optional/test/optional.cpp index d2f0c3f3..6407ac14 100644 --- a/libs/optional/test/optional.cpp +++ b/libs/optional/test/optional.cpp @@ -337,6 +337,10 @@ namespace testspr { int v = 12345; TESTSPR_ASSERT(sprout::get_optional_value_or(opt3, v) == 12345); } + + // sprout::to_hash, sprout::hash + TESTSPR_BOTH_ASSERT(sprout::to_hash(opt1) == sprout::hash()(opt1)); + TESTSPR_BOTH_ASSERT(sprout::to_hash(opt1) != sprout::to_hash(opt2)); } } } // namespace testspr diff --git a/libs/string/test/string.cpp b/libs/string/test/string.cpp index 1de8be36..1f881969 100644 --- a/libs/string/test/string.cpp +++ b/libs/string/test/string.cpp @@ -13,8 +13,8 @@ namespace testspr { using namespace sprout; { SPROUT_STATIC_CONSTEXPR char cstr[] = "foobar1234"; - SPROUT_STATIC_CONSTEXPR auto str1 = to_string(cstr); - SPROUT_STATIC_CONSTEXPR auto str2 = to_string("hogehoge"); + SPROUT_STATIC_CONSTEXPR auto str1 = sprout::to_string(cstr); + SPROUT_STATIC_CONSTEXPR auto str2 = sprout::to_string("hogehoge"); TESTSPR_BOTH_ASSERT((std::is_same const>::value)); TESTSPR_BOTH_ASSERT((std::is_same const>::value)); @@ -73,39 +73,39 @@ namespace testspr { // swap { - auto s1 = to_string("abc"); - auto s2 = to_string("ABC"); + auto s1 = sprout::to_string("abc"); + auto s2 = sprout::to_string("ABC"); s1.swap(s2); TESTSPR_ASSERT(s1[0] == 'A'); } // assign { - auto s = to_string("abc"); - s.assign(to_string("ABC")); + auto s = sprout::to_string("abc"); + s.assign(sprout::to_string("ABC")); TESTSPR_ASSERT(s.size() == 3); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); - s.assign(to_string("ABC"), 0, 2); + auto s = sprout::to_string("abc"); + s.assign(sprout::to_string("ABC"), 0, 2); TESTSPR_ASSERT(s.size() == 2); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); + auto s = sprout::to_string("abc"); s.assign("ABC", 2); TESTSPR_ASSERT(s.size() == 2); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); + auto s = sprout::to_string("abc"); s.assign("ABC"); TESTSPR_ASSERT(s.size() == 3); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); + auto s = sprout::to_string("abc"); s.assign(1, 'A'); TESTSPR_ASSERT(s.size() == 1); TESTSPR_ASSERT(s[0] == 'A'); @@ -113,19 +113,19 @@ namespace testspr { // operator= { - auto s = to_string("abc"); - s = to_string("ABC"); + auto s = sprout::to_string("abc"); + s = sprout::to_string("ABC"); TESTSPR_ASSERT(s.size() == 3); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); + auto s = sprout::to_string("abc"); s = "ABC"; TESTSPR_ASSERT(s.size() == 3); TESTSPR_ASSERT(s[0] == 'A'); } { - auto s = to_string("abc"); + auto s = sprout::to_string("abc"); s = 'A'; TESTSPR_ASSERT(s.size() == 1); TESTSPR_ASSERT(s[0] == 'A'); @@ -133,7 +133,7 @@ namespace testspr { // find TESTSPR_BOTH_ASSERT(str1.find(str2) == npos); - TESTSPR_BOTH_ASSERT(str1.find(to_string("bar")) == 3); + TESTSPR_BOTH_ASSERT(str1.find(sprout::to_string("bar")) == 3); TESTSPR_BOTH_ASSERT(str1.find(str2.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find("bar") == 3); TESTSPR_BOTH_ASSERT(str1.find(str2.c_str(), 0, 3) == npos); @@ -142,7 +142,7 @@ namespace testspr { // rfind TESTSPR_BOTH_ASSERT(str1.rfind(str2) == npos); - TESTSPR_BOTH_ASSERT(str1.rfind(to_string("bar")) == 3); + TESTSPR_BOTH_ASSERT(str1.rfind(sprout::to_string("bar")) == 3); TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.rfind("bar") == 3); TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str(), npos, 3) == npos); @@ -150,8 +150,8 @@ namespace testspr { TESTSPR_BOTH_ASSERT(str1.rfind('b') == 3); // find_first_of - TESTSPR_BOTH_ASSERT(str1.find_first_of(to_string("vwxyz")) == npos); - TESTSPR_BOTH_ASSERT(str1.find_first_of(to_string("rab")) == 3); + TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::to_string("vwxyz")) == npos); + TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::to_string("rab")) == 3); TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz") == npos); TESTSPR_BOTH_ASSERT(str1.find_first_of("rab") == 3); TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz", 0, 3) == npos); @@ -159,8 +159,8 @@ namespace testspr { TESTSPR_BOTH_ASSERT(str1.find_first_of('b') == 3); // find_last_of - TESTSPR_BOTH_ASSERT(str1.find_last_of(to_string("vwxyz")) == npos); - TESTSPR_BOTH_ASSERT(str1.find_last_of(to_string("rab")) == 5); + TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::to_string("vwxyz")) == npos); + TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::to_string("rab")) == 5); TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz") == npos); TESTSPR_BOTH_ASSERT(str1.find_last_of("rab") == 5); TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz", npos, 3) == npos); @@ -169,7 +169,7 @@ namespace testspr { // find_first_not_of TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1) == npos); - TESTSPR_BOTH_ASSERT(str1.find_first_not_of(to_string("foo")) == 3); + TESTSPR_BOTH_ASSERT(str1.find_first_not_of(sprout::to_string("foo")) == 3); TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find_first_not_of("foo") == 3); TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str(), 0, 10) == npos); @@ -178,7 +178,7 @@ namespace testspr { // find_last_not_of TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1) == npos); - TESTSPR_BOTH_ASSERT(str1.find_last_not_of(to_string("4321")) == 5); + TESTSPR_BOTH_ASSERT(str1.find_last_not_of(sprout::to_string("4321")) == 5); TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find_last_not_of("4321") == 5); TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str(), npos, 10) == npos); @@ -201,14 +201,14 @@ namespace testspr { // compare TESTSPR_BOTH_ASSERT(str1.compare(str1) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(to_string("zzzz")) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(to_string("aaaa")) > 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, to_string("foo")) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, to_string("zzzz")) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(0, 3, to_string("aaaa")) > 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, to_string("foo"), 0, 3) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, to_string("zzzz"), 0, 3) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(0, 3, to_string("aaaa"), 0, 3) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(sprout::to_string("zzzz")) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(sprout::to_string("aaaa")) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("foo")) == 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("zzzz")) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::to_string("aaaa")) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("foo"), 0, 3) == 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("zzzz"), 0, 3) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::to_string("aaaa"), 0, 3) > 0); TESTSPR_BOTH_ASSERT(str1.compare(str1.c_str()) == 0); TESTSPR_BOTH_ASSERT(str1.compare("zzzz") < 0); TESTSPR_BOTH_ASSERT(str1.compare("aaaa") > 0); @@ -241,7 +241,7 @@ namespace testspr { { #ifdef SPROUT_CONFIG_USE_INDEX_ITERATOR_IMPLEMENTATION // ! Error in GCC4.7 - SPROUT_STATIC_CONSTEXPR auto str3 = str1 + to_string("hogehoge"); + SPROUT_STATIC_CONSTEXPR auto str3 = str1 + sprout::to_string("hogehoge"); TESTSPR_BOTH_ASSERT(str3 == "foobar1234hogehoge"); #endif @@ -283,10 +283,34 @@ namespace testspr { // operator basic_string { - SPROUT_STATIC_CONSTEXPR string_t<10>::type str3 = to_string("foobar"); + SPROUT_STATIC_CONSTEXPR string_t<10>::type str3 = sprout::to_string("foobar"); TESTSPR_BOTH_ASSERT(str3 == "foobar"); TESTSPR_BOTH_ASSERT(str3.size() == 6); } + + // get + TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(str1) == 'f'); + TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(str1) == 'o'); + { + auto str3 = str1; + TESTSPR_ASSERT(sprout::tuples::get<0>(str3) == 'f'); + TESTSPR_ASSERT(sprout::tuples::get<1>(str3) == 'o'); + } + + // tuple_size + TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 10); + + // tuple_element + TESTSPR_BOTH_ASSERT((std::is_same::type, char const>::value)); + TESTSPR_BOTH_ASSERT((std::is_same::type, char const>::value)); + + // is_string + TESTSPR_BOTH_ASSERT(sprout::is_string::value); + TESTSPR_BOTH_ASSERT(!sprout::is_string::value); + + // sprout::to_hash, sprout::hash + TESTSPR_BOTH_ASSERT(sprout::to_hash(str1) == sprout::hash()(str1)); + TESTSPR_BOTH_ASSERT(sprout::to_hash(str1) != sprout::to_hash(str2)); } } } // namespace testspr diff --git a/libs/tuple/test/tuple.cpp b/libs/tuple/test/tuple.cpp index a2b43668..05569740 100644 --- a/libs/tuple/test/tuple.cpp +++ b/libs/tuple/test/tuple.cpp @@ -221,8 +221,12 @@ namespace testspr { TESTSPR_BOTH_ASSERT(sprout::tuples::is_tuple::value); TESTSPR_BOTH_ASSERT(!sprout::tuples::is_tuple::value); - // hash_value - TESTSPR_BOTH_ASSERT((hash_value(sprout::tuples::tuple(1, 2)) != 0)); + // sprout::to_hash, sprout::hash + { + typedef sprout::tuples::tuple type; + TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1, 2)) == sprout::hash()(type(1, 2))); + TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1, 2)) != sprout::to_hash(type())); + } } } } // namespace testspr diff --git a/libs/variant/test/variant.cpp b/libs/variant/test/variant.cpp index 9b764b6b..8e690ff2 100644 --- a/libs/variant/test/variant.cpp +++ b/libs/variant/test/variant.cpp @@ -213,6 +213,17 @@ namespace testspr { // tuple_element TESTSPR_BOTH_ASSERT((std::is_same::type, int const>::value)); TESTSPR_BOTH_ASSERT((std::is_same::type, double const>::value)); + + // is_variant + TESTSPR_BOTH_ASSERT(sprout::is_variant::value); + TESTSPR_BOTH_ASSERT(!sprout::is_variant::value); + + // sprout::to_hash, sprout::hash + { + typedef sprout::variant type; + TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1)) == sprout::hash()(type(1))); + TESTSPR_BOTH_ASSERT(sprout::to_hash(type(1)) != sprout::to_hash(type())); + } } } } // namespace testspr diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 337fac46..da2b0ec5 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -6,9 +6,9 @@ #include #include #include +#include #include #include #include -#include #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP diff --git a/sprout/variant.hpp b/sprout/variant.hpp index ebadbee3..8d74f64d 100644 --- a/sprout/variant.hpp +++ b/sprout/variant.hpp @@ -2,11 +2,13 @@ #define SPROUT_VARIANT_HPP #include +#include #include #include #include #include #include +#include #include #include #include diff --git a/sprout/variant/type_traits.hpp b/sprout/variant/type_traits.hpp new file mode 100644 index 00000000..ca81ef41 --- /dev/null +++ b/sprout/variant/type_traits.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_VARIANT_TYPE_TRAITS_HPP +#define SPROUT_VARIANT_TYPE_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + // + // is_variant + // + template + struct is_variant + : public std::false_type + {}; + template + struct is_variant + : public sprout::is_variant + {}; + template + struct is_variant + : public sprout::is_variant + {}; + template + struct is_variant > + : public std::true_type + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_VARIANT_TYPE_TRAITS_HPP diff --git a/sprout/variant/variant.hpp b/sprout/variant/variant.hpp index 5a62bf7c..aae6f2c1 100644 --- a/sprout/variant/variant.hpp +++ b/sprout/variant/variant.hpp @@ -16,12 +16,10 @@ #include #include #include +#include #include namespace sprout { - template - class variant; - namespace detail { template class variant_impl { diff --git a/sprout/variant/variant_fwd.hpp b/sprout/variant/variant_fwd.hpp new file mode 100644 index 00000000..b315afc2 --- /dev/null +++ b/sprout/variant/variant_fwd.hpp @@ -0,0 +1,11 @@ +#ifndef SPROUT_VARIANT_VARIANT_FWD_HPP +#define SPROUT_VARIANT_VARIANT_FWD_HPP + +#include + +namespace sprout { + template + class variant; +} // namespace sprout + +#endif // #ifndef SPROUT_VARIANT_VARIANT_FWD_HPP