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);
|
||||
}
|
||||
|
||||
|
||||
// get
|
||||
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/tuple/tuple/tuple_fwd.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/comparison.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
#include <sprout/tuple/tuple/ignore.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/hash.hpp>
|
||||
|
||||
|
|
|
@ -40,17 +40,26 @@ namespace sprout {
|
|||
: public std::tuple_element<I, T>
|
||||
{};
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T const>
|
||||
: public sprout::tuples::tuple_element<I, T>
|
||||
{};
|
||||
struct tuple_element<I, T const> {
|
||||
public:
|
||||
typedef typename std::add_const<
|
||||
typename sprout::tuples::tuple_element<I, T>::type
|
||||
>::type type;
|
||||
};
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T volatile>
|
||||
: public sprout::tuples::tuple_element<I, T>
|
||||
{};
|
||||
struct tuple_element<I, T volatile> {
|
||||
public:
|
||||
typedef typename std::add_volatile<
|
||||
typename sprout::tuples::tuple_element<I, T>::type
|
||||
>::type type;
|
||||
};
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element<I, T const volatile>
|
||||
: public sprout::tuples::tuple_element<I, T>
|
||||
{};
|
||||
struct tuple_element<I, T const volatile> {
|
||||
public:
|
||||
typedef typename std::add_cv<
|
||||
typename sprout::tuples::tuple_element<I, T>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template<std::size_t I, typename Head, typename... Tail>
|
||||
|
|
|
@ -14,7 +14,8 @@ namespace sprout {
|
|||
// make_tuple
|
||||
//
|
||||
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)...);
|
||||
}
|
||||
|
||||
|
@ -22,7 +23,8 @@ namespace sprout {
|
|||
// forward_as_tuple
|
||||
//
|
||||
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)...);
|
||||
}
|
||||
|
||||
|
@ -30,7 +32,8 @@ namespace sprout {
|
|||
// tie
|
||||
//
|
||||
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...);
|
||||
}
|
||||
|
||||
|
@ -86,7 +89,7 @@ namespace sprout {
|
|||
template<typename... Tuples>
|
||||
struct tuple_cat
|
||||
: public sprout::tuples::result_of::detail::tuple_cat_impl<
|
||||
typename std::remove_reference<Tuples>::type...
|
||||
typename std::decay<Tuples>::type...
|
||||
>
|
||||
{};
|
||||
} // namespace result_of
|
||||
|
@ -109,23 +112,6 @@ namespace sprout {
|
|||
|
||||
template<typename Result, typename IndexTuple, typename... Tuples>
|
||||
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>
|
||||
struct tuple_cat_impl<Result, sprout::index_tuple<> > {
|
||||
public:
|
||||
|
@ -135,6 +121,22 @@ namespace sprout {
|
|||
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
|
||||
//
|
||||
// tuple_cat
|
||||
|
|
|
@ -93,6 +93,8 @@ namespace sprout {
|
|||
template<std::size_t Index>
|
||||
class tuple_impl<Index> {
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
protected:
|
||||
|
@ -124,6 +126,8 @@ namespace sprout {
|
|||
, private sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value>
|
||||
{
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
public:
|
||||
|
@ -142,11 +146,11 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR inherited_type const& tail(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
protected:
|
||||
public:
|
||||
void swap(tuple_impl& t)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval<Head&>()), head(t)))
|
||||
&& SPROUT_NOEXCEPT_EXPR(inherited_type::swap(tail(t)))
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval<tuple_impl&>()), head(t)))
|
||||
&& SPROUT_NOEXCEPT_EXPR(std::declval<inherited_type&>().swap(tail(t)))
|
||||
)
|
||||
{
|
||||
sprout::swap(head(*this), head(t));
|
||||
|
@ -223,52 +227,6 @@ namespace sprout {
|
|||
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
|
||||
|
||||
//
|
||||
|
@ -278,7 +236,7 @@ namespace sprout {
|
|||
class tuple
|
||||
: public sprout::tuples::detail::tuple_impl<0, Types...>
|
||||
{
|
||||
public:
|
||||
private:
|
||||
typedef sprout::tuples::detail::tuple_impl<0, Types...> inherited_type;
|
||||
public:
|
||||
// tuple construction
|
||||
|
@ -338,7 +296,7 @@ namespace sprout {
|
|||
}
|
||||
// tuple swap
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,14 @@ namespace testspr {
|
|||
testspr::print_ln(testspr::typename_of<T>());
|
||||
}
|
||||
|
||||
//
|
||||
// print_type
|
||||
//
|
||||
template<typename T>
|
||||
void print_type() {
|
||||
testspr::print_typename<testspr::id<T> >();
|
||||
}
|
||||
|
||||
//
|
||||
// print_hl
|
||||
//
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "../libs/array/test/array.cpp"
|
||||
#include "../libs/string/test/string.cpp"
|
||||
#include "../libs/bitset/test/bitset.cpp"
|
||||
#include "../libs/tuple/test/tuple.cpp"
|
||||
#include "../libs/optional/test/optional.cpp"
|
||||
#include "../libs/algorithm/test/algorithm.cpp"
|
||||
#include "../libs/random/test/random.cpp"
|
||||
|
@ -22,6 +23,7 @@ namespace testspr {
|
|||
testspr::array_test();
|
||||
testspr::string_test();
|
||||
testspr::bitset_test();
|
||||
testspr::tuple_test();
|
||||
testspr::optional_test();
|
||||
testspr::algorithm_test();
|
||||
testspr::random_test();
|
||||
|
|
|
@ -45,6 +45,15 @@
|
|||
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||
|
||||
namespace testspr {
|
||||
//
|
||||
// do_nothing
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
do_nothing(T const&) SPROUT_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// is_even
|
||||
//
|
||||
|
@ -226,7 +235,7 @@ namespace testspr {
|
|||
// distance
|
||||
//
|
||||
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) {
|
||||
return first == last ? 0
|
||||
: 1 + testspr::distance(first + 1, last)
|
||||
|
@ -246,7 +255,7 @@ namespace testspr {
|
|||
;
|
||||
}
|
||||
template<typename Range1, typename Range2>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal(Range1 const& range1, Range2 const& range2) {
|
||||
return testspr::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2));
|
||||
}
|
||||
|
@ -255,7 +264,7 @@ namespace testspr {
|
|||
// is_found
|
||||
//
|
||||
template<class InputIterator, typename T>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_found(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last ? false
|
||||
: *first == value ? true
|
||||
|
@ -263,7 +272,7 @@ namespace testspr {
|
|||
;
|
||||
}
|
||||
template<typename Range, typename T>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_found(Range const& range, T const& value) {
|
||||
return testspr::is_found(sprout::begin(range), sprout::end(range), value);
|
||||
}
|
||||
|
@ -272,21 +281,21 @@ namespace testspr {
|
|||
// count
|
||||
//
|
||||
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) {
|
||||
return first == last ? 0
|
||||
: (*first == value ? 1 : 0) + testspr::count(first + 1, last, value)
|
||||
;
|
||||
}
|
||||
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) {
|
||||
return testspr::count(sprout::begin(range), sprout::end(range), value);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation_impl(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||
|
@ -304,7 +313,7 @@ namespace testspr {
|
|||
// is_permutation
|
||||
//
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2
|
||||
|
@ -313,7 +322,7 @@ namespace testspr {
|
|||
return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2);
|
||||
}
|
||||
template<typename Range1, typename Range2>
|
||||
SPROUT_CONSTEXPR bool
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(Range1 const& range1, Range2 const& range2) {
|
||||
return testspr::is_permutation(
|
||||
sprout::begin(range1), sprout::end(range1),
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
#endif
|
||||
|
||||
namespace testspr {
|
||||
//
|
||||
// id
|
||||
//
|
||||
template<typename T>
|
||||
struct id {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
//
|
||||
// typename_of
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue