1 /* Copyright (C) 2016 Murray Cumming
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/
19 #include <sigc++/tuple-utils/tuple_start.h>
23 test_tuple_type_start() {
25 using type_tuple = std::tuple<int, short, double>;
26 using type_tuple_start = sigc::internal::tuple_type_start<type_tuple, 1>::type;
27 using type_tuple_expected = std::tuple<int>;
29 static_assert(std::is_same<type_tuple_start, type_tuple_expected>::value,
30 "unexpected type_tuple_start type");
34 using type_tuple = std::tuple<int, short, double>;
35 using type_tuple_start = sigc::internal::tuple_type_start<type_tuple, 2>::type;
36 using type_tuple_expected = std::tuple<int, short>;
38 static_assert(std::is_same<type_tuple_start, type_tuple_expected>::value,
39 "unexpected type_tuple_start type");
43 using type_tuple = std::tuple<int, short, double>;
44 using type_tuple_start = sigc::internal::tuple_type_start<type_tuple, 3>::type;
45 using type_tuple_expected = std::tuple<int, short, double>;
47 static_assert(std::is_same<type_tuple_start, type_tuple_expected>::value,
48 "unexpected type_tuple_start type");
56 std::make_tuple(nullptr, std::string("hello"), std::string("world"));
57 auto t_prefix = sigc::internal::tuple_start<3>(t_original);
59 static_assert(std::tuple_size<decltype(t_prefix)>::value == 3,
60 "unexpected tuple_start()ed tuple size.");
62 assert(std::get<0>(t_prefix) == nullptr);
63 assert(std::get<1>(t_prefix) == "hello");
64 assert(std::get<2>(t_prefix) == "world");
66 static_assert(std::is_same<decltype(t_prefix), decltype(t_original)>::value,
67 "unexpected start()ed tuple type");
72 std::make_tuple(nullptr, std::string("hello"), std::string("world"));
73 auto t_prefix = sigc::internal::tuple_start<2>(t_original);
75 static_assert(std::tuple_size<decltype(t_prefix)>::value == 2,
76 "unexpected tuple_start()ed tuple size.");
78 assert(std::get<0>(t_prefix) == nullptr);
79 assert(std::get<1>(t_prefix) == "hello");
81 using type_tuple_prefix = std::tuple<std::nullptr_t, std::string>;
82 static_assert(std::is_same<decltype(t_prefix), type_tuple_prefix>::value,
83 "unexpected start()ed tuple type");
88 std::make_tuple(nullptr, std::string("hello"), std::string("world"));
89 auto t_prefix = sigc::internal::tuple_start<1>(t_original);
91 static_assert(std::tuple_size<decltype(t_prefix)>::value == 1,
92 "unexpected tuple_start()ed tuple size.");
94 assert(std::get<0>(t_prefix) == nullptr);
96 using type_tuple_prefix = std::tuple<std::nullptr_t>;
97 static_assert(std::is_same<decltype(t_prefix), type_tuple_prefix>::value,
98 "unexpected start()ed tuple type");
103 test_tuple_start_stdref() {
104 std::string a = "yadda";
105 std::string b = "yaddayadda";
106 auto t_larger = std::make_tuple(std::ref(a), std::ref(b), 1);
108 auto t_prefix = sigc::internal::tuple_start<2>(t_larger);
111 //This works, but it's not what we are testing here:
112 //assert(std::get<0>(t_larger) == "hello");
114 assert(std::get<0>(t_prefix) == "hello");
115 assert(std::get<1>(t_prefix) == "world");
120 test_tuple_start_constexpr() {
121 constexpr auto str_hello = "hello";
122 constexpr auto str_world = "hello";
124 constexpr auto t_original =
125 std::make_tuple(nullptr, str_hello, str_world);
126 constexpr auto t_prefix = sigc::internal::tuple_start<2>(t_original);
128 static_assert(std::tuple_size<decltype(t_prefix)>::value == 2,
129 "unexpected tuple_start()ed tuple size.");
131 assert(std::get<0>(t_prefix) == nullptr);
132 assert(std::get<1>(t_prefix) == str_hello);
137 test_tuple_type_start();
139 test_tuple_start_stdref();
141 test_tuple_start_constexpr();