From 7d212fd67dc3f580fc9a0cd5ce77a14519bda31b Mon Sep 17 00:00:00 2001 From: badair Date: Thu, 31 Mar 2016 01:59:08 -0500 Subject: [PATCH] adding function example for is_constexpr --- example/is_constexpr/function.cpp | 36 ++++++++++++++++++++ include/callable_traits/detail/any_arg.hpp | 4 --- qtcreator/main/main.cpp | 38 +++++++++++++++------- 3 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 example/is_constexpr/function.cpp diff --git a/example/is_constexpr/function.cpp b/example/is_constexpr/function.cpp new file mode 100644 index 0000000..d8cdef0 --- /dev/null +++ b/example/is_constexpr/function.cpp @@ -0,0 +1,36 @@ + +/*! +Copyright (c) 2016 Barrett Adair + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +*/ + +#include +#include + +// NOTE: Due to non-compliance in MSVC, is_constexpr always +// returns std::false_type on that compiler, which causes +// the static asserts below to fail. + +namespace ct = callable_traits; + +constexpr int foo(const int&) { + return 1; +} + +int bar(const int&) { + return 1; +} + +// for is_constexpr calls, function pointers must +// be passed as std::integral_constants +using F = std::integral_constant; +using B = std::integral_constant; + +static_assert(ct::is_constexpr(F{}), ""); +static_assert(ct::is_constexpr(), ""); +static_assert(!ct::is_constexpr(B{}), ""); +static_assert(!ct::is_constexpr(), ""); + +int main() { return 0; } diff --git a/include/callable_traits/detail/any_arg.hpp b/include/callable_traits/detail/any_arg.hpp index b279c3f..fff1338 100644 --- a/include/callable_traits/detail/any_arg.hpp +++ b/include/callable_traits/detail/any_arg.hpp @@ -65,10 +65,6 @@ namespace callable_traits { template const any_arg_evaluated any_arg_evaluated::value = {}; -#undef CALLABLE_TRAITS_CONCAT_ -#undef CALLABLE_TRAITS_CONCAT -#undef CALLABLE_TRAITS_INITIALIZE_ANY_ARG_VALUE - //any_arg is only used in unevaluated contexts template struct any_arg : any_arg_evaluated { diff --git a/qtcreator/main/main.cpp b/qtcreator/main/main.cpp index 4b3e211..d8cdef0 100644 --- a/qtcreator/main/main.cpp +++ b/qtcreator/main/main.cpp @@ -1,22 +1,36 @@ -/* -Copyright Barrett Adair 2016 + +/*! +Copyright (c) 2016 Barrett Adair + 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 #include -struct foo{}; +// NOTE: Due to non-compliance in MSVC, is_constexpr always +// returns std::false_type on that compiler, which causes +// the static asserts below to fail. namespace ct = callable_traits; -using pmf = void(foo::*)(); -using test = ct::add_const_qualifier; -using expect = void(foo::*)() const; - -static_assert(std::is_same{}, ""); - -int main() { - return 0; +constexpr int foo(const int&) { + return 1; } + +int bar(const int&) { + return 1; +} + +// for is_constexpr calls, function pointers must +// be passed as std::integral_constants +using F = std::integral_constant; +using B = std::integral_constant; + +static_assert(ct::is_constexpr(F{}), ""); +static_assert(ct::is_constexpr(), ""); +static_assert(!ct::is_constexpr(B{}), ""); +static_assert(!ct::is_constexpr(), ""); + +int main() { return 0; }