mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix tuples::tuple_element, tuples::tuple_cat
add test tuple
This commit is contained in:
parent
d75283355c
commit
cb803dbd14
10 changed files with 323 additions and 92 deletions
|
@ -304,7 +304,6 @@ namespace testspr {
|
||||||
TESTSPR_ASSERT(!opt3);
|
TESTSPR_ASSERT(!opt3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get
|
// get
|
||||||
TESTSPR_BOTH_ASSERT(sprout::get(opt1) == 1234);
|
TESTSPR_BOTH_ASSERT(sprout::get(opt1) == 1234);
|
||||||
{
|
{
|
||||||
|
|
235
libs/tuple/test/tuple.cpp
Normal file
235
libs/tuple/test/tuple.cpp
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
#ifndef SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP
|
||||||
|
#define SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <sprout/tuple/tuple.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void tuple_test() {
|
||||||
|
using namespace sprout;
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup1 = sprout::tuples::tuple<int, double>(1, 1.0);
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup2 = sprout::tuples::tuple<int, double>();
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>();
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 0);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(tup1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(1, 1.0);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(1l);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(1l, 1.0f);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(1l, 1.0f, '-');
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(sprout::tuples::tuple<long>(1l));
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(sprout::tuples::tuple<long, float>(1l, 1.0f));
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple<int, double>(sprout::tuples::tuple<long, float, char>(1l, 1.0f, '-'));
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// operator=
|
||||||
|
{
|
||||||
|
auto tup3 = tup2;
|
||||||
|
tup3 = sprout::tuples::tuple<int, double>(1, 1.0);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto tup3 = tup2;
|
||||||
|
tup3 = sprout::tuples::tuple<long>(1l);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto tup3 = tup2;
|
||||||
|
tup3 = sprout::tuples::tuple<long, float>(1l, 1.0f);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto tup3 = tup2;
|
||||||
|
tup3 = sprout::tuples::tuple<long, float, char>(1l, 1.0f, '-');
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// swap
|
||||||
|
{
|
||||||
|
auto tup3 = tup1;
|
||||||
|
auto tup4 = tup2;
|
||||||
|
tup3.swap(tup4);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 0);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup4) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup4) == 1.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto tup3 = tup1;
|
||||||
|
auto tup4 = tup2;
|
||||||
|
swap(tup3, tup4);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 0);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 0.0);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup4) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup4) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::tuple_size
|
||||||
|
TESTSPR_BOTH_ASSERT(std::tuple_size<decltype(tup1)>::value == 2);
|
||||||
|
|
||||||
|
// std::tuple_element
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<std::tuple_element<0, decltype(tup1)>::type, int const>::value));
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<std::tuple_element<1, decltype(tup1)>::type, double const>::value));
|
||||||
|
|
||||||
|
// operator==
|
||||||
|
TESTSPR_BOTH_ASSERT(!(tup1 == tup2));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 == sprout::tuples::tuple<int, double>(1, 1.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 == sprout::tuples::tuple<long, float>())));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 == sprout::tuples::tuple<long, float>(1l, 1.0f)));
|
||||||
|
|
||||||
|
// operator!=
|
||||||
|
TESTSPR_BOTH_ASSERT(tup1 != tup2);
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 != sprout::tuples::tuple<int, double>(1, 1.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 != sprout::tuples::tuple<long, float>()));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 != sprout::tuples::tuple<long, float>(1l, 1.0f))));
|
||||||
|
|
||||||
|
// operator<
|
||||||
|
TESTSPR_BOTH_ASSERT(!(tup1 < tup2));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple<int, double>(1, -1.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple<int, double>(1, 1.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 < sprout::tuples::tuple<int, double>(1, 2.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple<long, float>())));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple<long, float>(1l, -1.0f))));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 < sprout::tuples::tuple<long, float>(1l, 1.0f))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 < sprout::tuples::tuple<long, float>(1l, 2.0f)));
|
||||||
|
|
||||||
|
// operator>
|
||||||
|
TESTSPR_BOTH_ASSERT(tup1 > tup2);
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple<int, double>(1, -1.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple<int, double>(1, 1.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple<int, double>(1, 2.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple<long, float>()));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 > sprout::tuples::tuple<long, float>(1l, -1.0f)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple<long, float>(1l, 1.0f))));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 > sprout::tuples::tuple<long, float>(1l, 2.0f))));
|
||||||
|
|
||||||
|
// operator<=
|
||||||
|
TESTSPR_BOTH_ASSERT(!(tup1 <= tup2));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple<int, double>(1, -1.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple<int, double>(1, 1.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple<int, double>(1, 2.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple<long, float>())));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 <= sprout::tuples::tuple<long, float>(1l, -1.0f))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple<long, float>(1l, 1.0f)));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 <= sprout::tuples::tuple<long, float>(1l, 2.0f)));
|
||||||
|
|
||||||
|
// operator>=
|
||||||
|
TESTSPR_BOTH_ASSERT(tup1 >= tup2);
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple<int, double>(1, -1.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple<int, double>(1, 1.0)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 >= sprout::tuples::tuple<int, double>(1, 2.0))));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple<long, float>()));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple<long, float>(1l, -1.0f)));
|
||||||
|
TESTSPR_BOTH_ASSERT((tup1 >= sprout::tuples::tuple<long, float>(1l, 1.0f)));
|
||||||
|
TESTSPR_BOTH_ASSERT((!(tup1 >= sprout::tuples::tuple<long, float>(1l, 2.0f))));
|
||||||
|
|
||||||
|
// get
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup1) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup1) == 1.0);
|
||||||
|
{
|
||||||
|
auto tup3 = tup1;
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tuple_size
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size<decltype(tup1)>::value == 2);
|
||||||
|
|
||||||
|
// tuple_element
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<0, decltype(tup1)>::type, int const>::value));
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<1, decltype(tup1)>::type, double const>::value));
|
||||||
|
|
||||||
|
// make_tuple
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::make_tuple(1, 1.0) == tup1);
|
||||||
|
|
||||||
|
// forward_as_tuple
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::forward_as_tuple(1, 1.0) == tup1);
|
||||||
|
|
||||||
|
// tie
|
||||||
|
{
|
||||||
|
auto v1 = 0;
|
||||||
|
auto v2 = 0.0;
|
||||||
|
TESTSPR_ASSERT(sprout::tuples::tie(v1, v2) == tup2);
|
||||||
|
|
||||||
|
sprout::tuples::tie(v1, v2) = tup1;
|
||||||
|
TESTSPR_ASSERT(v1 == 1);
|
||||||
|
TESTSPR_ASSERT(v2 == 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// tuple_cat
|
||||||
|
{
|
||||||
|
typedef sprout::tuples::result_of::tuple_cat<decltype(tup1), decltype(tup2)>::type concatenated_type;
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size<concatenated_type>::value == 4);
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<0, concatenated_type>::type, int>::value));
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<1, concatenated_type>::type, double>::value));
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<2, concatenated_type>::type, int>::value));
|
||||||
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<3, concatenated_type>::type, double>::value));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple_cat(tup1, tup2);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<2>(tup3) == 0);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<3>(tup3) == 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// is_tuple
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::tuples::is_tuple<decltype(tup1)>::value);
|
||||||
|
TESTSPR_BOTH_ASSERT(!sprout::tuples::is_tuple<int>::value);
|
||||||
|
|
||||||
|
// hash_value
|
||||||
|
TESTSPR_BOTH_ASSERT((sprout::hash_value(sprout::tuples::tuple<int, int>(1, 2)) != 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::tuple_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_TUPLE_TEST_TUPLE_CPP
|
|
@ -4,10 +4,10 @@
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple.hpp>
|
#include <sprout/tuple/tuple/tuple.hpp>
|
||||||
|
#include <sprout/tuple/tuple/comparison.hpp>
|
||||||
#include <sprout/tuple/tuple/get.hpp>
|
#include <sprout/tuple/tuple/get.hpp>
|
||||||
#include <sprout/tuple/tuple/ignore.hpp>
|
#include <sprout/tuple/tuple/ignore.hpp>
|
||||||
#include <sprout/tuple/tuple/make_tuple.hpp>
|
#include <sprout/tuple/tuple/make_tuple.hpp>
|
||||||
#include <sprout/tuple/tuple/comparison.hpp>
|
|
||||||
#include <sprout/tuple/tuple/type_traits.hpp>
|
#include <sprout/tuple/tuple/type_traits.hpp>
|
||||||
#include <sprout/tuple/tuple/hash.hpp>
|
#include <sprout/tuple/tuple/hash.hpp>
|
||||||
|
|
||||||
|
|
|
@ -40,17 +40,26 @@ namespace sprout {
|
||||||
: public std::tuple_element<I, T>
|
: public std::tuple_element<I, T>
|
||||||
{};
|
{};
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
struct tuple_element<I, T const>
|
struct tuple_element<I, T const> {
|
||||||
: public sprout::tuples::tuple_element<I, T>
|
public:
|
||||||
{};
|
typedef typename std::add_const<
|
||||||
|
typename sprout::tuples::tuple_element<I, T>::type
|
||||||
|
>::type type;
|
||||||
|
};
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
struct tuple_element<I, T volatile>
|
struct tuple_element<I, T volatile> {
|
||||||
: public sprout::tuples::tuple_element<I, T>
|
public:
|
||||||
{};
|
typedef typename std::add_volatile<
|
||||||
|
typename sprout::tuples::tuple_element<I, T>::type
|
||||||
|
>::type type;
|
||||||
|
};
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
struct tuple_element<I, T const volatile>
|
struct tuple_element<I, T const volatile> {
|
||||||
: public sprout::tuples::tuple_element<I, T>
|
public:
|
||||||
{};
|
typedef typename std::add_cv<
|
||||||
|
typename sprout::tuples::tuple_element<I, T>::type
|
||||||
|
>::type type;
|
||||||
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<std::size_t I, typename Head, typename... Tail>
|
template<std::size_t I, typename Head, typename... Tail>
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace sprout {
|
||||||
// make_tuple
|
// make_tuple
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<typename std::decay<Types>::type...> make_tuple(Types&&... args) {
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<typename std::decay<Types>::type...>
|
||||||
|
make_tuple(Types&&... args) {
|
||||||
return sprout::tuples::tuple<typename std::decay<Types>::type...>(sprout::forward<Types>(args)...);
|
return sprout::tuples::tuple<typename std::decay<Types>::type...>(sprout::forward<Types>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +23,8 @@ namespace sprout {
|
||||||
// forward_as_tuple
|
// forward_as_tuple
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types&&...> forward_as_tuple(Types&&... args) SPROUT_NOEXCEPT {
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types&&...>
|
||||||
|
forward_as_tuple(Types&&... args) SPROUT_NOEXCEPT {
|
||||||
return sprout::tuples::tuple<Types&&...>(sprout::forward<Types>(args)...);
|
return sprout::tuples::tuple<Types&&...>(sprout::forward<Types>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +32,8 @@ namespace sprout {
|
||||||
// tie
|
// tie
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
inline sprout::tuples::tuple<Types&...> tie(Types&... args) SPROUT_NOEXCEPT {
|
inline sprout::tuples::tuple<Types&...>
|
||||||
|
tie(Types&... args) SPROUT_NOEXCEPT {
|
||||||
return sprout::tuples::tuple<Types&...>(args...);
|
return sprout::tuples::tuple<Types&...>(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +89,7 @@ namespace sprout {
|
||||||
template<typename... Tuples>
|
template<typename... Tuples>
|
||||||
struct tuple_cat
|
struct tuple_cat
|
||||||
: public sprout::tuples::result_of::detail::tuple_cat_impl<
|
: public sprout::tuples::result_of::detail::tuple_cat_impl<
|
||||||
typename std::remove_reference<Tuples>::type...
|
typename std::decay<Tuples>::type...
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
} // namespace result_of
|
} // namespace result_of
|
||||||
|
@ -109,23 +112,6 @@ namespace sprout {
|
||||||
|
|
||||||
template<typename Result, typename IndexTuple, typename... Tuples>
|
template<typename Result, typename IndexTuple, typename... Tuples>
|
||||||
struct tuple_cat_impl;
|
struct tuple_cat_impl;
|
||||||
template<typename Result, sprout::index_t... Indexes, typename Head, typename... Tail>
|
|
||||||
struct tuple_cat_impl<Result, sprout::index_tuple<Indexes...>, Head, Tail...> {
|
|
||||||
public:
|
|
||||||
template<typename... Args>
|
|
||||||
static SPROUT_CONSTEXPR Result
|
|
||||||
call(Head&& head, Tail&&... tail, Args&&... args) {
|
|
||||||
return sprout::tuples::detail::tuple_cat_impl<
|
|
||||||
Result,
|
|
||||||
typename sprout::tuples::detail::tuple_cat_1st_indexes<Tail...>::type,
|
|
||||||
Tail...
|
|
||||||
>::call(
|
|
||||||
sprout::forward<Tail>(tail)...,
|
|
||||||
sprout::forward<Args>(args)...,
|
|
||||||
sprout::tuples::get<Indexes>(sprout::forward<Head>(head))...
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct tuple_cat_impl<Result, sprout::index_tuple<> > {
|
struct tuple_cat_impl<Result, sprout::index_tuple<> > {
|
||||||
public:
|
public:
|
||||||
|
@ -135,6 +121,22 @@ namespace sprout {
|
||||||
return Result(sprout::forward<Args>(args)...);
|
return Result(sprout::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
template<typename Result, sprout::index_t... Indexes, typename Head, typename... Tail>
|
||||||
|
struct tuple_cat_impl<Result, sprout::index_tuple<Indexes...>, Head, Tail...> {
|
||||||
|
public:
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
static SPROUT_CONSTEXPR Result
|
||||||
|
call(T&& t, Args&&... args) {
|
||||||
|
return sprout::tuples::detail::tuple_cat_impl<
|
||||||
|
Result,
|
||||||
|
typename sprout::tuples::detail::tuple_cat_1st_indexes<Tail...>::type,
|
||||||
|
Tail...
|
||||||
|
>::call(
|
||||||
|
sprout::forward<Args>(args)...,
|
||||||
|
sprout::tuples::get<Indexes>(sprout::forward<T>(t))...
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
//
|
//
|
||||||
// tuple_cat
|
// tuple_cat
|
||||||
|
|
|
@ -93,6 +93,8 @@ namespace sprout {
|
||||||
template<std::size_t Index>
|
template<std::size_t Index>
|
||||||
class tuple_impl<Index> {
|
class tuple_impl<Index> {
|
||||||
public:
|
public:
|
||||||
|
template<typename...>
|
||||||
|
friend class tuple;
|
||||||
template<std::size_t, typename...>
|
template<std::size_t, typename...>
|
||||||
friend class sprout::tuples::detail::tuple_impl;
|
friend class sprout::tuples::detail::tuple_impl;
|
||||||
protected:
|
protected:
|
||||||
|
@ -124,6 +126,8 @@ namespace sprout {
|
||||||
, private sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value>
|
, private sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
template<typename...>
|
||||||
|
friend class tuple;
|
||||||
template<std::size_t, typename...>
|
template<std::size_t, typename...>
|
||||||
friend class sprout::tuples::detail::tuple_impl;
|
friend class sprout::tuples::detail::tuple_impl;
|
||||||
public:
|
public:
|
||||||
|
@ -142,11 +146,11 @@ namespace sprout {
|
||||||
static SPROUT_CONSTEXPR inherited_type const& tail(tuple_impl const& t) SPROUT_NOEXCEPT {
|
static SPROUT_CONSTEXPR inherited_type const& tail(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
protected:
|
public:
|
||||||
void swap(tuple_impl& t)
|
void swap(tuple_impl& t)
|
||||||
SPROUT_NOEXCEPT_EXPR(
|
SPROUT_NOEXCEPT_EXPR(
|
||||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval<Head&>()), head(t)))
|
SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval<tuple_impl&>()), head(t)))
|
||||||
&& SPROUT_NOEXCEPT_EXPR(inherited_type::swap(tail(t)))
|
&& SPROUT_NOEXCEPT_EXPR(std::declval<inherited_type&>().swap(tail(t)))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sprout::swap(head(*this), head(t));
|
sprout::swap(head(*this), head(t));
|
||||||
|
@ -223,52 +227,6 @@ namespace sprout {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool Head, bool... Tail>
|
|
||||||
struct and_impl;
|
|
||||||
template<>
|
|
||||||
struct and_impl<true>
|
|
||||||
: public std::true_type
|
|
||||||
{};
|
|
||||||
template<>
|
|
||||||
struct and_impl<false>
|
|
||||||
: public std::false_type
|
|
||||||
{};
|
|
||||||
template<bool... Tail>
|
|
||||||
struct and_impl<true, Tail...>
|
|
||||||
: public std::integral_constant<bool, sprout::tuples::detail::and_impl<Tail...>::value>
|
|
||||||
{};
|
|
||||||
template<bool... Tail>
|
|
||||||
struct and_impl<false, Tail...>
|
|
||||||
: public std::false_type
|
|
||||||
{};
|
|
||||||
template<typename... Types>
|
|
||||||
struct and_
|
|
||||||
: public sprout::tuples::detail::and_impl<Types::value...>
|
|
||||||
{};
|
|
||||||
|
|
||||||
template<bool Head, bool... Tail>
|
|
||||||
struct or_impl;
|
|
||||||
template<>
|
|
||||||
struct or_impl<true>
|
|
||||||
: public std::true_type
|
|
||||||
{};
|
|
||||||
template<>
|
|
||||||
struct or_impl<false>
|
|
||||||
: public std::false_type
|
|
||||||
{};
|
|
||||||
template<bool... Tail>
|
|
||||||
struct or_impl<true, Tail...>
|
|
||||||
: public std::true_type
|
|
||||||
{};
|
|
||||||
template<bool... Tail>
|
|
||||||
struct or_impl<false, Tail...>
|
|
||||||
: public std::integral_constant<bool, sprout::tuples::detail::or_impl<Tail...>::value>
|
|
||||||
{};
|
|
||||||
template<typename... Types>
|
|
||||||
struct or_
|
|
||||||
: public sprout::tuples::detail::and_impl<Types::value...>
|
|
||||||
{};
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -278,7 +236,7 @@ namespace sprout {
|
||||||
class tuple
|
class tuple
|
||||||
: public sprout::tuples::detail::tuple_impl<0, Types...>
|
: public sprout::tuples::detail::tuple_impl<0, Types...>
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
typedef sprout::tuples::detail::tuple_impl<0, Types...> inherited_type;
|
typedef sprout::tuples::detail::tuple_impl<0, Types...> inherited_type;
|
||||||
public:
|
public:
|
||||||
// tuple construction
|
// tuple construction
|
||||||
|
@ -338,7 +296,7 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
// tuple swap
|
// tuple swap
|
||||||
void swap(tuple& other)
|
void swap(tuple& other)
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(inherited_type::swap(other)))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<inherited_type&>().swap(other)))
|
||||||
{
|
{
|
||||||
inherited_type::swap(other);
|
inherited_type::swap(other);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,14 @@ namespace testspr {
|
||||||
testspr::print_ln(testspr::typename_of<T>());
|
testspr::print_ln(testspr::typename_of<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// print_type
|
||||||
|
//
|
||||||
|
template<typename T>
|
||||||
|
void print_type() {
|
||||||
|
testspr::print_typename<testspr::id<T> >();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// print_hl
|
// print_hl
|
||||||
//
|
//
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "../libs/array/test/array.cpp"
|
#include "../libs/array/test/array.cpp"
|
||||||
#include "../libs/string/test/string.cpp"
|
#include "../libs/string/test/string.cpp"
|
||||||
#include "../libs/bitset/test/bitset.cpp"
|
#include "../libs/bitset/test/bitset.cpp"
|
||||||
|
#include "../libs/tuple/test/tuple.cpp"
|
||||||
#include "../libs/optional/test/optional.cpp"
|
#include "../libs/optional/test/optional.cpp"
|
||||||
#include "../libs/algorithm/test/algorithm.cpp"
|
#include "../libs/algorithm/test/algorithm.cpp"
|
||||||
#include "../libs/random/test/random.cpp"
|
#include "../libs/random/test/random.cpp"
|
||||||
|
@ -22,6 +23,7 @@ namespace testspr {
|
||||||
testspr::array_test();
|
testspr::array_test();
|
||||||
testspr::string_test();
|
testspr::string_test();
|
||||||
testspr::bitset_test();
|
testspr::bitset_test();
|
||||||
|
testspr::tuple_test();
|
||||||
testspr::optional_test();
|
testspr::optional_test();
|
||||||
testspr::algorithm_test();
|
testspr::algorithm_test();
|
||||||
testspr::random_test();
|
testspr::random_test();
|
||||||
|
|
|
@ -45,6 +45,15 @@
|
||||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||||
|
|
||||||
namespace testspr {
|
namespace testspr {
|
||||||
|
//
|
||||||
|
// do_nothing
|
||||||
|
//
|
||||||
|
template<typename T>
|
||||||
|
inline SPROUT_CONSTEXPR bool
|
||||||
|
do_nothing(T const&) SPROUT_NOEXCEPT {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// is_even
|
// is_even
|
||||||
//
|
//
|
||||||
|
@ -226,7 +235,7 @@ namespace testspr {
|
||||||
// distance
|
// distance
|
||||||
//
|
//
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||||
distance(InputIterator first, InputIterator last) {
|
distance(InputIterator first, InputIterator last) {
|
||||||
return first == last ? 0
|
return first == last ? 0
|
||||||
: 1 + testspr::distance(first + 1, last)
|
: 1 + testspr::distance(first + 1, last)
|
||||||
|
@ -246,7 +255,7 @@ namespace testspr {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Range1, typename Range2>
|
template<typename Range1, typename Range2>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
equal(Range1 const& range1, Range2 const& range2) {
|
equal(Range1 const& range1, Range2 const& range2) {
|
||||||
return testspr::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2));
|
return testspr::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2));
|
||||||
}
|
}
|
||||||
|
@ -255,7 +264,7 @@ namespace testspr {
|
||||||
// is_found
|
// is_found
|
||||||
//
|
//
|
||||||
template<class InputIterator, typename T>
|
template<class InputIterator, typename T>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_found(InputIterator first, InputIterator last, T const& value) {
|
is_found(InputIterator first, InputIterator last, T const& value) {
|
||||||
return first == last ? false
|
return first == last ? false
|
||||||
: *first == value ? true
|
: *first == value ? true
|
||||||
|
@ -263,7 +272,7 @@ namespace testspr {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Range, typename T>
|
template<typename Range, typename T>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_found(Range const& range, T const& value) {
|
is_found(Range const& range, T const& value) {
|
||||||
return testspr::is_found(sprout::begin(range), sprout::end(range), value);
|
return testspr::is_found(sprout::begin(range), sprout::end(range), value);
|
||||||
}
|
}
|
||||||
|
@ -272,21 +281,21 @@ namespace testspr {
|
||||||
// count
|
// count
|
||||||
//
|
//
|
||||||
template<typename InputIterator, typename T>
|
template<typename InputIterator, typename T>
|
||||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||||
count(InputIterator first, InputIterator last, T const& value) {
|
count(InputIterator first, InputIterator last, T const& value) {
|
||||||
return first == last ? 0
|
return first == last ? 0
|
||||||
: (*first == value ? 1 : 0) + testspr::count(first + 1, last, value)
|
: (*first == value ? 1 : 0) + testspr::count(first + 1, last, value)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Range, typename T>
|
template<typename Range, typename T>
|
||||||
SPROUT_CONSTEXPR typename std::iterator_traits<typename Range::const_iterator>::difference_type
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<typename Range::const_iterator>::difference_type
|
||||||
count(Range const& range, T const& value) {
|
count(Range const& range, T const& value) {
|
||||||
return testspr::count(sprout::begin(range), sprout::end(range), value);
|
return testspr::count(sprout::begin(range), sprout::end(range), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_permutation_impl(
|
is_permutation_impl(
|
||||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
ForwardIterator2 first2, ForwardIterator2 last2,
|
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||||
|
@ -304,7 +313,7 @@ namespace testspr {
|
||||||
// is_permutation
|
// is_permutation
|
||||||
//
|
//
|
||||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_permutation(
|
is_permutation(
|
||||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||||
ForwardIterator2 first2, ForwardIterator2 last2
|
ForwardIterator2 first2, ForwardIterator2 last2
|
||||||
|
@ -313,7 +322,7 @@ namespace testspr {
|
||||||
return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2);
|
return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2);
|
||||||
}
|
}
|
||||||
template<typename Range1, typename Range2>
|
template<typename Range1, typename Range2>
|
||||||
SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_permutation(Range1 const& range1, Range2 const& range2) {
|
is_permutation(Range1 const& range1, Range2 const& range2) {
|
||||||
return testspr::is_permutation(
|
return testspr::is_permutation(
|
||||||
sprout::begin(range1), sprout::end(range1),
|
sprout::begin(range1), sprout::end(range1),
|
||||||
|
|
|
@ -11,6 +11,15 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace testspr {
|
namespace testspr {
|
||||||
|
//
|
||||||
|
// id
|
||||||
|
//
|
||||||
|
template<typename T>
|
||||||
|
struct id {
|
||||||
|
public:
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// typename_of
|
// typename_of
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue