Files
callable_traits/example/can_invoke_constexpr/function_pointer.cpp
2016-04-01 19:35:40 -05:00

39 lines
1.1 KiB
C++

/*!
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 <type_traits>
#include <callable_traits/callable_traits.hpp>
namespace ct = callable_traits;
constexpr int seven(int) {
return 7;
}
using seven_c = std::integral_constant<decltype(&seven), &seven>;
// The first call to can_invoke_constexpr returns std::true_type
// because `seven` is a constexpr function, and valid INVOKE arguments
// are passed. The second call to can_invoke_constexpr returns
// std::false_type, because the arguments are not valid to INVOKE
static_assert(ct::can_invoke_constexpr(seven_c{}, 0), "");
static_assert(!ct::can_invoke_constexpr(seven_c{}, nullptr), "");
int eight(int) {
return 7;
}
using eight_c = std::integral_constant<decltype(&eight), &eight>;
// `eight` is NOT a constexpr function, so can_invoke_constexpr
// returns `std::false_type` even for valid INVOKE arguments.
static_assert(!ct::can_invoke_constexpr(eight_c{}, 0), "");
static_assert(!ct::can_invoke_constexpr(eight_c{}, nullptr), "");
int main() {}