Files
callable_traits/example/args.cpp

81 lines
2.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 <callable_traits/config.hpp>
#ifdef CALLABLE_TRAITS_DISABLE_ABOMINABLE_FUNCTIONS
int main(){ return 0; }
#else
//[ args
#include <type_traits>
#include <memory>
#include <callable_traits/callable_traits.hpp>
namespace ct = callable_traits;
template<typename T, typename Expect>
void test(){
// this example shows how callable_traits::args
// bevaves consistently for many different types
using args = ct::args<T>;
static_assert(std::is_same<args, Expect>::value, "");
}
int main() {
{
auto lamda = [](int, float&, const char*){};
using lam = decltype(lamda);
using expect = std::tuple<int, float&, const char*>;
test<lam, expect>();
test<lam&, expect>();
test<lam&&, expect>();
test<lam const &, expect>();
}
{
struct foo;
using pmf = void(foo::*)(int, float&, const char*);
using expect = std::tuple<foo&, int, float&, const char*>;
test<pmf, expect>();
test<pmf&, expect>();
test<pmf&&, expect>();
test<pmf const &, expect>();
}
{
using function_ptr = void(*)(int, float&, const char*);
using expect = std::tuple<int, float&, const char*>;
test<function_ptr, expect>();
test<function_ptr&, expect>();
test<function_ptr&&, expect>();
test<function_ptr const &, expect>();
}
{
using function_ref = void(&)(int, float&, const char*);
using expect = std::tuple<int, float&, const char*>;
test<function_ref, expect>();
}
{
using function = void(int, float&, const char*);
using expect = std::tuple<int, float&, const char*>;
test<function, expect>();
}
{
using abominable = void(int, float&, const char*) const;
using expect = std::tuple<int, float&, const char*>;
test<abominable, expect>();
}
}
//]
#endif //#ifdef CALLABLE_TRAITS_DISABLE_ABOMINABLE_FUNCTIONS