From 6fcb6824910882369061d8476f4ffad8ab08bcbf Mon Sep 17 00:00:00 2001 From: badair Date: Sun, 17 Apr 2016 14:55:15 -0500 Subject: [PATCH] parameter container operations tests also removing qualified_function_type --- include/callable_traits/callable_traits.hpp | 20 +++-- include/callable_traits/detail/function.hpp | 9 ++ include/callable_traits/insert_at.hpp | 6 +- include/callable_traits/is_callable.hpp | 32 +++++++ include/callable_traits/overwrite_at.hpp | 6 +- include/callable_traits/pop_back.hpp | 6 +- include/callable_traits/pop_front.hpp | 6 +- .../qualified_function_type.hpp | 50 ----------- .../{remove_at.txt => remove_at.hpp} | 6 +- test/insert_at_function.cpp | 62 ++++++++++++++ test/insert_at_function_ptr.cpp | 62 ++++++++++++++ test/insert_at_function_reference.cpp | 62 ++++++++++++++ test/insert_at_pmf.cpp | 64 ++++++++++++++ test/is_callable.cpp | 46 ++++++++++ test/overwrite_at_function.cpp | 55 ++++++++++++ test/overwrite_at_function_ptr.cpp | 55 ++++++++++++ test/overwrite_at_function_reference.cpp | 55 ++++++++++++ test/overwrite_at_pmf.cpp | 63 ++++++++++++++ test/pop_back_function.cpp | 47 ++++++++++ test/pop_back_function_ptr.cpp | 47 ++++++++++ test/pop_back_function_reference.cpp | 47 ++++++++++ test/pop_back_pmf.cpp | 49 +++++++++++ test/pop_front_function.cpp | 41 +++++++++ test/remove_at_function.cpp | 83 ++++++++++++++++++ test/remove_at_function_ptr.cpp | 83 ++++++++++++++++++ test/remove_at_function_reference.cpp | 83 ++++++++++++++++++ test/remove_at_pmf.cpp | 85 +++++++++++++++++++ 27 files changed, 1157 insertions(+), 73 deletions(-) create mode 100644 include/callable_traits/is_callable.hpp delete mode 100644 include/callable_traits/qualified_function_type.hpp rename include/callable_traits/{remove_at.txt => remove_at.hpp} (85%) create mode 100644 test/insert_at_function.cpp create mode 100644 test/insert_at_function_ptr.cpp create mode 100644 test/insert_at_function_reference.cpp create mode 100644 test/insert_at_pmf.cpp create mode 100644 test/is_callable.cpp create mode 100644 test/overwrite_at_function.cpp create mode 100644 test/overwrite_at_function_ptr.cpp create mode 100644 test/overwrite_at_function_reference.cpp create mode 100644 test/overwrite_at_pmf.cpp create mode 100644 test/pop_back_function.cpp create mode 100644 test/pop_back_function_ptr.cpp create mode 100644 test/pop_back_function_reference.cpp create mode 100644 test/pop_back_pmf.cpp create mode 100644 test/pop_front_function.cpp create mode 100644 test/remove_at_function.cpp create mode 100644 test/remove_at_function_ptr.cpp create mode 100644 test/remove_at_function_reference.cpp create mode 100644 test/remove_at_pmf.cpp diff --git a/include/callable_traits/callable_traits.hpp b/include/callable_traits/callable_traits.hpp index 9c40c8b..b1c8a39 100644 --- a/include/callable_traits/callable_traits.hpp +++ b/include/callable_traits/callable_traits.hpp @@ -11,12 +11,13 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_CALLABLE_TRAITS_HPP #include +#include #include #include #include #include -#include #include +#include #include #include #include @@ -28,28 +29,31 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include +#include #include #include +#include #include #include #include #include #include -#include #include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include #include -#include -#include -#include -#include +#include #include #endif diff --git a/include/callable_traits/detail/function.hpp b/include/callable_traits/detail/function.hpp index 843ca65..47a9499 100644 --- a/include/callable_traits/detail/function.hpp +++ b/include/callable_traits/detail/function.hpp @@ -186,6 +186,15 @@ namespace callable_traits { template using pop_front = typename base::template pop_front&; + + template + using insert_at = typename base::template insert_at&; + + template + using remove_at = typename base::template remove_at&; + + template + using overwrite_at = typename base::template overwrite_at&; }; template diff --git a/include/callable_traits/insert_at.hpp b/include/callable_traits/insert_at.hpp index edc291b..ff467f3 100644 --- a/include/callable_traits/insert_at.hpp +++ b/include/callable_traits/insert_at.hpp @@ -27,20 +27,20 @@ namespace callable_traits { namespace permissive { - template + template using insert_at = detail::fallback_if_invalid< typename detail::traits::template insert_at, T>; } namespace verbose { - template + template using insert_at = detail::fail_if_invalid< typename detail::traits::template insert_at, detail::insert_at_error>; } - template + template using insert_at = detail::fail_if_invalid< typename detail::traits::template insert_at, detail::insert_at_error>; diff --git a/include/callable_traits/is_callable.hpp b/include/callable_traits/is_callable.hpp new file mode 100644 index 0000000..a02b37d --- /dev/null +++ b/include/callable_traits/is_callable.hpp @@ -0,0 +1,32 @@ +/*! +@file + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_IS_CALLABLE_HPP +#define CALLABLE_TRAITS_IS_CALLABLE_HPP + +#include +#include +#include + +namespace callable_traits { + + template + static constexpr inline auto + is_callable() { + return std::integral_constant().value >= 0>{}; + } + + template + static constexpr inline auto + is_callable(T&&) { + return is_callable(); + } +} + +#endif //CALLABLE_TRAITS_IS_CALLABLE_HPP diff --git a/include/callable_traits/overwrite_at.hpp b/include/callable_traits/overwrite_at.hpp index 6b0230c..d855bbe 100644 --- a/include/callable_traits/overwrite_at.hpp +++ b/include/callable_traits/overwrite_at.hpp @@ -27,20 +27,20 @@ namespace callable_traits { namespace permissive { - template + template using overwrite_at = detail::fallback_if_invalid< typename detail::traits::template overwrite_at, T>; } namespace verbose { - template + template using overwrite_at = detail::fail_if_invalid< typename detail::traits::template overwrite_at, detail::overwrite_at_error>; } - template + template using overwrite_at = detail::fail_if_invalid< typename detail::traits::template overwrite_at, detail::overwrite_at_error>; diff --git a/include/callable_traits/pop_back.hpp b/include/callable_traits/pop_back.hpp index fdd715c..fd9dae0 100644 --- a/include/callable_traits/pop_back.hpp +++ b/include/callable_traits/pop_back.hpp @@ -27,20 +27,20 @@ namespace callable_traits { namespace permissive { - template + template using pop_back = detail::fallback_if_invalid< typename detail::traits::template pop_back, T>; } namespace verbose { - template + template using pop_back = detail::fail_if_invalid< typename detail::traits::template pop_back, detail::pop_back_error>; } - template + template using pop_back = detail::fail_if_invalid< typename detail::traits::template pop_back, detail::pop_back_error>; diff --git a/include/callable_traits/pop_front.hpp b/include/callable_traits/pop_front.hpp index f4246c1..5a45524 100644 --- a/include/callable_traits/pop_front.hpp +++ b/include/callable_traits/pop_front.hpp @@ -27,20 +27,20 @@ namespace callable_traits { namespace permissive { - template + template using pop_front = detail::fallback_if_invalid< typename detail::traits::template pop_front, T>; } namespace verbose { - template + template using pop_front = detail::fail_if_invalid< typename detail::traits::template pop_front, detail::pop_front_error>; } - template + template using pop_front = detail::fail_if_invalid< typename detail::traits::template pop_front, detail::pop_front_error>; diff --git a/include/callable_traits/qualified_function_type.hpp b/include/callable_traits/qualified_function_type.hpp deleted file mode 100644 index 9b58b8e..0000000 --- a/include/callable_traits/qualified_function_type.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_QUALIFIED_FUNCTION_TYPE_HPP -#define CALLABLE_TRAITS_QUALIFIED_FUNCTION_TYPE_HPP - -#include - -namespace callable_traits { - - namespace detail { - - template - struct qualified_function_type_error { - - static_assert(Sfinae, - "Unable to determine the qualified function type for " - "type T in callable_traits::qualified_function_type."); - }; - } - - namespace permissive { - - template - using qualified_function_type = detail::fallback_if_invalid< - typename detail::traits::qualified_function_type, - T>; - } - - namespace verbose { - - template - using qualified_function_type = detail::fail_if_invalid< - typename detail::traits::qualified_function_type, - detail::qualified_function_type_error>; - } - - template - using qualified_function_type = detail::fail_if_invalid< - typename detail::traits::qualified_function_type, - detail::qualified_function_type_error>; -} - -#endif diff --git a/include/callable_traits/remove_at.txt b/include/callable_traits/remove_at.hpp similarity index 85% rename from include/callable_traits/remove_at.txt rename to include/callable_traits/remove_at.hpp index 55ab819..ede3943 100644 --- a/include/callable_traits/remove_at.txt +++ b/include/callable_traits/remove_at.hpp @@ -27,20 +27,20 @@ namespace callable_traits { namespace permissive { - template + template using remove_at = detail::fallback_if_invalid< typename detail::traits::template remove_at, T>; } namespace verbose { - template + template using remove_at = detail::fail_if_invalid< typename detail::traits::template remove_at, detail::remove_at_error>; } - template + template using remove_at = detail::fail_if_invalid< typename detail::traits::template remove_at, detail::remove_at_error>; diff --git a/test/insert_at_function.cpp b/test/insert_at_function.cpp new file mode 100644 index 0000000..5bf6eb3 --- /dev/null +++ b/test/insert_at_function.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<0, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<1, f, int, char>; + using expect = sig, int, char, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<4, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<5, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int, char>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/insert_at_function_ptr.cpp b/test/insert_at_function_ptr.cpp new file mode 100644 index 0000000..7f63261 --- /dev/null +++ b/test/insert_at_function_ptr.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(* volatile &)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<0, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<1, f, int, char>; + using expect = sig, int, char, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<4, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<5, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int, char>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/insert_at_function_reference.cpp b/test/insert_at_function_reference.cpp new file mode 100644 index 0000000..8420732 --- /dev/null +++ b/test/insert_at_function_reference.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(&)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<0, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<1, f, int, char>; + using expect = sig, int, char, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<4, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<5, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int, char>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/insert_at_pmf.cpp b/test/insert_at_pmf.cpp new file mode 100644 index 0000000..2697bff --- /dev/null +++ b/test/insert_at_pmf.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +struct foo; + +template +using sig = int(foo::*)(Ts...) const; + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<0, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<1, f, int, char>; + using expect = sig, int, char, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<4, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::insert_at<5, f, int, char>; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int, char>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/is_callable.cpp b/test/is_callable.cpp new file mode 100644 index 0000000..b719926 --- /dev/null +++ b/test/is_callable.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace callable_traits { + + template + static constexpr inline auto + is_callable() { + return std::integral_constant().value >= 0>{}; + } + + template + static constexpr inline auto + is_callable(T&&) { + return is_callable(); + } +} + +namespace ct = callable_traits; + +void foo() {} + +struct bar { + template + auto operator()(T&& t) { + return t; + } +}; + +static_assert(ct::is_callable(foo), ""); +static_assert(ct::is_callable(&foo), ""); +static_assert(ct::is_callable(), ""); +static_assert(ct::is_callable(), ""); +static_assert(ct::is_callable(), ""); + +#ifndef CALLABLE_TRAITS_DISABLE_ARITY_RANGES +static_assert(ct::is_callable(bar{}), ""); +#endif //#ifndef CALLABLE_TRAITS_DISABLE_ARITY_RANGES + +int main() {} \ No newline at end of file diff --git a/test/overwrite_at_function.cpp b/test/overwrite_at_function.cpp new file mode 100644 index 0000000..1cce5c8 --- /dev/null +++ b/test/overwrite_at_function.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<0, f, int, char>; + using expect = sig, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<1, f, int, char>; + using expect = sig, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<4, f, int, char, short, void*>; + using expect = sig, N<1>, N<2>, N<3>, int, char, short, void*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/overwrite_at_function_ptr.cpp b/test/overwrite_at_function_ptr.cpp new file mode 100644 index 0000000..d460354 --- /dev/null +++ b/test/overwrite_at_function_ptr.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(*)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<0, f, int, char>; + using expect = sig, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<1, f, int, char>; + using expect = sig, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<4, f, int, char, short, void*>; + using expect = sig, N<1>, N<2>, N<3>, int, char, short, void*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/overwrite_at_function_reference.cpp b/test/overwrite_at_function_reference.cpp new file mode 100644 index 0000000..2ab7b39 --- /dev/null +++ b/test/overwrite_at_function_reference.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(&)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<0, f, int, char>; + using expect = sig, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<1, f, int, char>; + using expect = sig, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<4, f, int, char, short, void*>; + using expect = sig, N<1>, N<2>, N<3>, int, char, short, void*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/overwrite_at_pmf.cpp b/test/overwrite_at_pmf.cpp new file mode 100644 index 0000000..4ed9ba8 --- /dev/null +++ b/test/overwrite_at_pmf.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +#ifdef CALLABLE_TRAITS_DISABLE_REFERENCE_QUALIFIERS +#define RREF +#else +#define RREF && +#endif + +namespace ct = callable_traits; + +template +struct N {}; + +struct foo; + +template +using sig = int(foo::* const)(Ts...) const volatile RREF; + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<0, f, int, char>; + using expect = sig, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<1, f, int, char>; + using expect = sig, int, char, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<2, f, int, char>; + using expect = sig, N<1>, int, char, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<3, f, int, char>; + using expect = sig, N<1>, N<2>, int, char>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::overwrite_at<4, f, int, char, short, void*>; + using expect = sig, N<1>, N<2>, N<3>, int, char, short, void*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/pop_back_function.cpp b/test/pop_back_function.cpp new file mode 100644 index 0000000..02bbdf2 --- /dev/null +++ b/test/pop_back_function.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(Ts...); + +int main() { + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/pop_back_function_ptr.cpp b/test/pop_back_function_ptr.cpp new file mode 100644 index 0000000..672672b --- /dev/null +++ b/test/pop_back_function_ptr.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = void(* const &)(Ts...); + +int main() { + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/pop_back_function_reference.cpp b/test/pop_back_function_reference.cpp new file mode 100644 index 0000000..aa43e86 --- /dev/null +++ b/test/pop_back_function_reference.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = const char*(&)(Ts...); + +int main() { + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/pop_back_pmf.cpp b/test/pop_back_pmf.cpp new file mode 100644 index 0000000..8544f0e --- /dev/null +++ b/test/pop_back_pmf.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +struct foo; + +template +using sig = void(foo::* const volatile)(Ts...); + +int main() { + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_back; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/pop_front_function.cpp b/test/pop_front_function.cpp new file mode 100644 index 0000000..809ff42 --- /dev/null +++ b/test/pop_front_function.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_front; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_front; + using expect = sig, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::pop_front; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/remove_at_function.cpp b/test/remove_at_function.cpp new file mode 100644 index 0000000..2b1aa91 --- /dev/null +++ b/test/remove_at_function.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<1, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<2, f>; + using expect = sig, N<1>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f>; + using expect = sig, N<1>, N<2>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 5>; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 3>; + using expect = sig, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f, 2>; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f, 1>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/remove_at_function_ptr.cpp b/test/remove_at_function_ptr.cpp new file mode 100644 index 0000000..354d4d4 --- /dev/null +++ b/test/remove_at_function_ptr.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(*&)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<1, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<2, f>; + using expect = sig, N<1>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f>; + using expect = sig, N<1>, N<2>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 5>; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 3>; + using expect = sig, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f, 2>; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f, 1>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/remove_at_function_reference.cpp b/test/remove_at_function_reference.cpp new file mode 100644 index 0000000..008d590 --- /dev/null +++ b/test/remove_at_function_reference.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +template +using sig = int(&)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<1, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<2, f>; + using expect = sig, N<1>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f>; + using expect = sig, N<1>, N<2>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 5>; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 3>; + using expect = sig, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f, 2>; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f, 1>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/remove_at_pmf.cpp b/test/remove_at_pmf.cpp new file mode 100644 index 0000000..50ffc68 --- /dev/null +++ b/test/remove_at_pmf.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include + +#ifndef CT_ASSERT +#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#endif //CT_ASSERT + +namespace ct = callable_traits; + +template +struct N {}; + +struct foo {}; + +template +using sig = void(foo::* const)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<1, f>; + using expect = sig, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<2, f>; + using expect = sig, N<1>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f>; + using expect = sig, N<1>, N<2>, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 5>; + using expect = sig<>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<0, f, 3>; + using expect = sig, N<4>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<3, f, 2>; + using expect = sig, N<1>, N<2>>; + CT_ASSERT(std::is_same::value); + } + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::remove_at<4, f, 1>; + using expect = sig, N<1>, N<2>, N<3>>; + CT_ASSERT(std::is_same::value); + } +} +