File: function_traits_asserts.hpp

package info (click to toggle)
libfplus 0.2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,904 kB
  • sloc: cpp: 27,543; javascript: 634; sh: 105; python: 103; makefile: 6
file content (57 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2015, Tobias Hermann and the FunctionalPlus contributors.
// https://github.com/Dobiasd/FunctionalPlus
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <fplus/internal/invoke.hpp>
#include <fplus/function_traits.hpp>

namespace fplus
{
namespace internal
{
template <typename T, typename...>
struct function_traits_asserts;

template <
    typename,
    typename F,
    typename... Args,
    typename std::enable_if<is_invocable<F, Args...>::value, int>::type = 0>
constexpr void trigger_static_asserts()
{
}

// Marks a variable as unused. Prevents the compiler warning
// for set but unused variables.
template<class T>
inline void unused(T&&) { }

template <typename Tag,
          typename F,
          typename... Args,
          typename std::enable_if<has_function_traits<F>::value &&
                                      !is_invocable<F, Args...>::value,
                                  int>::type = 0>
constexpr void trigger_static_asserts()
{
    // don't perform checks if function_traits<F> doesn't exist
    unused(function_traits_asserts<Tag, F, Args...>{});
}

template <typename,
          typename F,
          typename... Args,
          typename std::enable_if<!has_function_traits<F>::value &&
                                      !is_invocable<F, Args...>::value,
                                  int>::type = 0>
constexpr void trigger_static_asserts()
{
  static_assert(sizeof(F) == 0,
                "F is not a Callable, or its definition is ill-formed");
}
}
}