From 7908670c427c8e9b01bbff3e78b8a706df7ed7ea Mon Sep 17 00:00:00 2001 From: badair Date: Sun, 17 Apr 2016 15:06:14 -0500 Subject: [PATCH] more push_back tests --- .appveyor.yml | 2 +- qtcreator/main/main.cpp | 325 ++++--------------------- qtcreator/main/main.pro | 2 + test/is_callable.cpp | 4 +- test/push_back_function.cpp | 29 +++ test/push_back_function_ptr.cpp | 29 +++ test/push_back_pmf.cpp | 29 +++ test/push_back_pmf_varargs.cpp | 29 +++ test/push_front_function.cpp | 35 +++ test/push_front_function_ptr.cpp | 29 +++ test/push_front_function_reference.cpp | 29 +++ test/push_front_pmf.cpp | 35 +++ test/push_front_pmf_varargs.cpp | 35 +++ 13 files changed, 325 insertions(+), 287 deletions(-) create mode 100644 test/push_back_function.cpp create mode 100644 test/push_back_function_ptr.cpp create mode 100644 test/push_back_pmf.cpp create mode 100644 test/push_back_pmf_varargs.cpp create mode 100644 test/push_front_function.cpp create mode 100644 test/push_front_function_ptr.cpp create mode 100644 test/push_front_function_reference.cpp create mode 100644 test/push_front_pmf.cpp create mode 100644 test/push_front_pmf_varargs.cpp diff --git a/.appveyor.yml b/.appveyor.yml index 9d85102..0364e4d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -36,4 +36,4 @@ build_script: set msbuild_exe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" - echo . | "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" check.vcxproj /t:build /p:Configuration=Debug /p:Platform=Win32 /v:d /nologo + echo . | "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" check.vcxproj /t:build /p:Configuration=Debug /p:Platform=Win32 /v:n /nologo diff --git a/qtcreator/main/main.cpp b/qtcreator/main/main.cpp index f7b4107..f0d40c5 100644 --- a/qtcreator/main/main.cpp +++ b/qtcreator/main/main.cpp @@ -1,301 +1,58 @@ -/* - -Copyright Barrett Adair 2015 +/*<- +Copyright Barrett Adair 2016 Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) +->*/ -*/ +#include +#ifdef CALLABLE_TRAITS_DISABLE_REFERENCE_QUALIFIERS +int main(){ return 0; } +#else +//[ add_member_const #include -#include -#include -#include - -#ifndef CT_ASSERT -#define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) -#endif //CT_ASSERT - -struct three_arg_function_object { - void operator()(char&&, float&, int = 0) {} -}; - -struct three_arg_function_object_with_varargs { - void operator()(volatile char&, const float&, int = 0, ...) {} -}; - -struct void_function_object { - void operator()() {} -}; - -struct vararg_function_object { - void operator()(...) {} -}; - -struct void_function_object_default { - void operator()(int = 0) {} -}; - -struct vararg_function_object_default { - void operator()(int = 0, ...) {} -}; - -struct template_function_object { - template - void operator()(A&&, B&, C) {} -}; - -struct variadic_template_function_object { - template - void operator()(Args&&...) {} -}; - -struct variadic_template_function_object_plus_one { - template - void operator()(T&&, Args&&...) {} -}; - -struct constrained_variadic_template_function_object { - template - typename std::enable_if::type operator()(Args...) {} -}; - -struct simple_overloaded_function_object { - void operator()(int, int) {} - void operator()(int, int, int, int, int) {} -}; - -struct overloaded_function_object { - void operator()(int) & {} - void operator()(int, int) && {} - void operator()(int, int, int) const & {} - void operator()(int, int, int, int) const && {} - void operator()(int, int, int, int, int) volatile & {} - void operator()(int, int, int, int, int, int) volatile && {} - void operator()(int, int, int, int, int, int, int) const volatile & {} - void operator()(int, int, int, int, int, int, int, int) const volatile && {} -}; - -void three_arg_function(char&&, float&, int = 0) {} -void three_arg_function_with_varargs(char&&, float&, int = 0, ...) {} - -void void_function() {} -void void_function_with_varargs(...) {} +#include namespace ct = callable_traits; -using std::is_same; -template< - typename T, - int ExpectedArity, - int ExpectedMinArity, - int ExpectedMaxArity, - std::size_t SearchLimit -> -void test_arity() { - CT_ASSERT(ct::arity() == ExpectedArity); - CT_ASSERT(ct::min_arity() == ExpectedMinArity); - CT_ASSERT(ct::max_arity() == ExpectedMaxArity); -} +struct foo {}; -template< - int ExpectedArity, - int ExpectedMinArity, - int ExpectedMaxArity, - std::size_t SearchLimit, - typename T -> -void test_arity(T&& t) { - - using arity_result = decltype(ct::arity(t)); - CT_ASSERT(arity_result{} == ExpectedArity); - - using min_arity_result = decltype(ct::min_arity(t)); - CT_ASSERT(min_arity_result{} == ExpectedMinArity); - - using max_arity_result = decltype(ct::max_arity(t)); - CT_ASSERT(max_arity_result{} == ExpectedMaxArity); -} - -constexpr const auto limit = ct::constants::arity_search_limit; -constexpr const auto limit_plus = limit + 1; -constexpr const auto limit_minus = limit - 1; - -static_assert(5 <= limit_minus, - "constants::arity_search_limit unexpectedly low for these test cases."); - -namespace ctd = ct::detail; int main() { { - //testing pmf without varargs - using F = three_arg_function_object; - using T = decltype(&F::operator()); - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 3, 3, limit>(&F::operator()); - test_arity<3, 3, 3, limit_plus>(&F::operator()); - test_arity<3, 3, 3, limit_minus>(&F::operator()); + using pmf = int(foo::*)(); + using expect = int(foo::*)() const; + using test = ct::add_member_const; + static_assert(std::is_same::value, ""); } { - //testing pmf with varargs - using F = three_arg_function_object_with_varargs; - using T = decltype(&F::operator()); - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 3, 3, limit>(&F::operator()); - test_arity<3, 3, 3, limit_plus>(&F::operator()); - test_arity<3, 3, 3, limit_minus>(&F::operator()); + // add_member_const doesn't change anything when + // the function type is already const. + using pmf = int(foo::*)() const &&; + using expect = int(foo::*)() const &&; + using test = ct::add_member_const; + static_assert(std::is_same::value, ""); } { - //testing function object without varargs - //min_arity will recognize default argument - using T = three_arg_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 2, 3, limit>(T{}); - test_arity<3, 2, 3, limit_plus>(T{}); - test_arity<3, 2, 3, limit_minus>(T{}); + using pmf = int(foo::*)() volatile &; + using expect = int(foo::*)() const volatile &; + using test = ct::add_member_const; + static_assert(std::is_same::value, ""); } { - //testing function object with varargs - //min_arity will recognize default argument - //max_arity will recognize the varargs - using T = three_arg_function_object_with_varargs; - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 2, limit, limit>(T{}); - test_arity<3, 2, limit_plus, limit_plus>(T{}); - test_arity<3, 2, limit_minus, limit_minus>(T{}); + // add_member_const can also be used with "abominable" + // function types. + using f = int(); + using expect = int() const; + using test = ct::add_member_const; + static_assert(std::is_same::value, ""); } { - //testing void function object without varargs - using T = void_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<0, 0, 0, limit>(T{}); - test_arity<0, 0, 0, limit_plus>(T{}); - test_arity<0, 0, 0, limit_minus>(T{}); - } { - //testing void function object with varargs - //max_arity will recognize the varargs - using T = vararg_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<0, 0, limit, limit>(T{}); - test_arity<0, 0, limit_plus, limit_plus>(T{}); - test_arity<0, 0, limit_minus, limit_minus>(T{}); - } { - //testing function object with default arg and no varargs - //min arity will recognize the default - using T = void_function_object_default; - test_arity(); - test_arity(); - test_arity(); - test_arity<1, 0, 1, limit>(T{}); - test_arity<1, 0, 1, limit_plus>(T{}); - test_arity<1, 0, 1, limit_minus>(T{}); - } { - //testing function object with default arg and varargs - //min arity will recognize the default - //max_arity will recognize the varargs - using T = vararg_function_object_default; - test_arity(); - test_arity(); - test_arity(); - test_arity<1, 0, limit, limit>(T{}); - test_arity<1, 0, limit_plus, limit_plus>(T{}); - test_arity<1, 0, limit_minus, limit_minus>(T{}); - } { - //testing templated function object - using T = template_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<-1, 3, 3, limit>(T{}); - test_arity<-1, 3, 3, limit_plus>(T{}); - test_arity<-1, 3, 3, limit_minus>(T{}); - } { - //testing templated function object - using T = variadic_template_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<-1, 0, limit, limit>(T{}); - test_arity<-1, 0, limit_plus, limit_plus>(T{}); - test_arity<-1, 0, limit_minus, limit_minus>(T{}); - } { - //testing templated function object (plus one required arg) - using T = variadic_template_function_object_plus_one; - test_arity(); - test_arity(); - test_arity(); - test_arity<-1, 1, limit, limit>(T{}); - test_arity<-1, 1, limit_plus, limit_plus>(T{}); - test_arity<-1, 1, limit_minus, limit_minus>(T{}); - } { - //testing overloaded function object with arity gap - using T = simple_overloaded_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity<-1, 2, 5, limit>(T{}); - test_arity<-1, 2, 5, limit_plus>(T{}); - test_arity<-1, 2, 5, limit_minus>(T{}); - } { - //testing cv/ref qualified overloads - using T = overloaded_function_object; - test_arity(); - test_arity(); - test_arity(); - test_arity(); - test_arity(); - -// MSVC doesn't know what to do with these -#ifndef CALLABLE_TRAITS_MSVC - test_arity(); - test_arity(); - test_arity(); -#endif + // add_member_const does not compile with function pointers, + // function references, function objects, or member data pointers. + // However, you can loosen this restriction somewhat by using the + // callable_traits::permissive namespace instead: + using f = int(*)(); + using expect = f; + using test = ct::permissive::add_member_const; + static_assert(std::is_same::value, ""); } - { - //testing function without varargs - using T = decltype(three_arg_function); - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 3, 3, limit>(&three_arg_function); - test_arity<3, 3, 3, limit_plus>(&three_arg_function); - test_arity<3, 3, 3, limit_minus>(&three_arg_function); - } { - //testing function with varargs - using T = decltype(three_arg_function_with_varargs); - test_arity(); - test_arity(); - test_arity(); - test_arity<3, 3, 3, limit>(&three_arg_function_with_varargs); - test_arity<3, 3, 3, limit_plus>(&three_arg_function_with_varargs); - test_arity<3, 3, 3, limit_minus>(&three_arg_function_with_varargs); - } { - //testing void function without varargs - using T = decltype(void_function); - test_arity(); - test_arity(); - test_arity(); - test_arity<0, 0, 0, limit>(&void_function); - test_arity<0, 0, 0, limit_plus>(&void_function); - test_arity<0, 0, 0, limit_minus>(&void_function); - } { - //testing void function with varargs - using T = decltype(void_function_with_varargs); - test_arity(); - test_arity(); - test_arity(); - test_arity<0, 0, 0, limit>(&void_function_with_varargs); - test_arity<0, 0, 0, limit_plus>(&void_function_with_varargs); - test_arity<0, 0, 0, limit_minus>(&void_function_with_varargs); - } - - return 0; } +//] +#endif //#ifdef CALLABLE_TRAITS_DISABLE_REFERENCE_QUALIFIERS diff --git a/qtcreator/main/main.pro b/qtcreator/main/main.pro index e0649ea..5fff443 100644 --- a/qtcreator/main/main.pro +++ b/qtcreator/main/main.pro @@ -1,8 +1,10 @@ TEMPLATE = app CONFIG += console -std=c++14 +#CONFIG += console -std=c++1y CONFIG -= qt app_bundle QMAKE_CXXFLAGS += -std=c++14 -Wall -Wextra -pedantic +#QMAKE_CXXFLAGS += -std=c++1y -Wall -Wextra -pedantic INCLUDEPATH += ../../include diff --git a/test/is_callable.cpp b/test/is_callable.cpp index b719926..7bc32d1 100644 --- a/test/is_callable.cpp +++ b/test/is_callable.cpp @@ -39,8 +39,8 @@ static_assert(ct::is_callable(), ""); static_assert(ct::is_callable(), ""); static_assert(ct::is_callable(), ""); -#ifndef CALLABLE_TRAITS_DISABLE_ARITY_RANGES +#ifndef CALLABLE_TRAITS_DISABLE_ARITY_RANGE static_assert(ct::is_callable(bar{}), ""); #endif //#ifndef CALLABLE_TRAITS_DISABLE_ARITY_RANGES -int main() {} \ No newline at end of file +int main() {} diff --git a/test/push_back_function.cpp b/test/push_back_function.cpp new file mode 100644 index 0000000..634e0be --- /dev/null +++ b/test/push_back_function.cpp @@ -0,0 +1,29 @@ +#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(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int&, char*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_back_function_ptr.cpp b/test/push_back_function_ptr.cpp new file mode 100644 index 0000000..751a40f --- /dev/null +++ b/test/push_back_function_ptr.cpp @@ -0,0 +1,29 @@ +#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(*)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int&, char*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_back_pmf.cpp b/test/push_back_pmf.cpp new file mode 100644 index 0000000..53b7b1e --- /dev/null +++ b/test/push_back_pmf.cpp @@ -0,0 +1,29 @@ +#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::* const &)(Ts...) const volatile; + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int&, char*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_back_pmf_varargs.cpp b/test/push_back_pmf_varargs.cpp new file mode 100644 index 0000000..d60b4dc --- /dev/null +++ b/test/push_back_pmf_varargs.cpp @@ -0,0 +1,29 @@ +#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::* const &)(Ts..., ...) const; + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int&, char*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_front_function.cpp b/test/push_front_function.cpp new file mode 100644 index 0000000..bbe0448 --- /dev/null +++ b/test/push_front_function.cpp @@ -0,0 +1,35 @@ +#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(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_front; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_front_function_ptr.cpp b/test/push_front_function_ptr.cpp new file mode 100644 index 0000000..9bea8cc --- /dev/null +++ b/test/push_front_function_ptr.cpp @@ -0,0 +1,29 @@ +#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(*)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_front; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_front_function_reference.cpp b/test/push_front_function_reference.cpp new file mode 100644 index 0000000..d5db8d8 --- /dev/null +++ b/test/push_front_function_reference.cpp @@ -0,0 +1,29 @@ +#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(&)(Ts...); + +int main() { + + { + using f = sig, N<1>, N<2>, N<3>, N<4>>; + using test = ct::push_back; + using expect = sig, N<1>, N<2>, N<3>, N<4>, int&, char*>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_front_pmf.cpp b/test/push_front_pmf.cpp new file mode 100644 index 0000000..7d7a5ad --- /dev/null +++ b/test/push_front_pmf.cpp @@ -0,0 +1,35 @@ +#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::push_front; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } +} + diff --git a/test/push_front_pmf_varargs.cpp b/test/push_front_pmf_varargs.cpp new file mode 100644 index 0000000..3d1d199 --- /dev/null +++ b/test/push_front_pmf_varargs.cpp @@ -0,0 +1,35 @@ +#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::push_front; + using expect = sig, N<1>, N<2>, N<3>, N<4>>; + CT_ASSERT(std::is_same::value); + } +} +