mirror of
https://github.com/boostorg/callable_traits.git
synced 2026-02-13 12:22:18 +00:00
adding function example for is_constexpr
This commit is contained in:
36
example/is_constexpr/function.cpp
Normal file
36
example/is_constexpr/function.cpp
Normal file
@@ -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 <type_traits>
|
||||
#include <callable_traits/callable_traits.hpp>
|
||||
|
||||
// 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<decltype(&foo), &foo>;
|
||||
using B = std::integral_constant<decltype(&bar), &bar>;
|
||||
|
||||
static_assert(ct::is_constexpr(F{}), "");
|
||||
static_assert(ct::is_constexpr<F>(), "");
|
||||
static_assert(!ct::is_constexpr(B{}), "");
|
||||
static_assert(!ct::is_constexpr<B>(), "");
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -65,10 +65,6 @@ namespace callable_traits {
|
||||
template<std::size_t I>
|
||||
const any_arg_evaluated<I> any_arg_evaluated<I>::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<std::size_t I = 0>
|
||||
struct any_arg : any_arg_evaluated<I> {
|
||||
|
||||
@@ -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 <type_traits>
|
||||
#include <callable_traits/callable_traits.hpp>
|
||||
|
||||
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<pmf>;
|
||||
using expect = void(foo::*)() const;
|
||||
|
||||
static_assert(std::is_same<test, expect>{}, "");
|
||||
|
||||
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<decltype(&foo), &foo>;
|
||||
using B = std::integral_constant<decltype(&bar), &bar>;
|
||||
|
||||
static_assert(ct::is_constexpr(F{}), "");
|
||||
static_assert(ct::is_constexpr<F>(), "");
|
||||
static_assert(!ct::is_constexpr(B{}), "");
|
||||
static_assert(!ct::is_constexpr<B>(), "");
|
||||
|
||||
int main() { return 0; }
|
||||
|
||||
Reference in New Issue
Block a user