File: composition.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 (111 lines) | stat: -rw-r--r-- 4,355 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 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/function_traits_asserts.hpp>

namespace fplus
{
namespace internal
{

struct bind_1st_of_2_tag
{
};

struct bind_2nd_of_2_tag
{
};

struct bind_1st_of_3_tag
{
};

struct bind_1st_and_2nd_of_3_tag
{
};

struct bind_2nd_and_3rd_of_3_tag
{
};

template <typename F, typename X, typename Y>
struct function_traits_asserts<bind_1st_of_2_tag, F, X, Y>
{
    static_assert(utils::function_traits<F>::arity == 2,
                  "Function must take two parameters.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    typedef typename utils::function_traits<F>::template arg<1>::type FIn1;
    static_assert(std::is_convertible<X, FIn0>::value,
                  "Function can not take bound parameter type");
    static_assert(std::is_convertible<Y, FIn1>::value,
                  "Function can not take provided parameter type");
};

template <typename F, typename X, typename Y>
struct function_traits_asserts<bind_2nd_of_2_tag, F, X, Y>
{
    static_assert(utils::function_traits<F>::arity == 2,
                  "Function must take two parameters.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    typedef typename utils::function_traits<F>::template arg<1>::type FIn1;
    static_assert(std::is_convertible<X, FIn0>::value,
                  "Function can not take provided parameter type");
    static_assert(std::is_convertible<Y, FIn1>::value,
                  "Function can not take bound parameter type");
};

template <typename F, typename X, typename Y, typename Z>
struct function_traits_asserts<bind_1st_of_3_tag, F, X, Y, Z>
{
    static_assert(utils::function_traits<F>::arity == 3,
                  "Function must take three parameters.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    typedef typename utils::function_traits<F>::template arg<1>::type FIn1;
    typedef typename utils::function_traits<F>::template arg<2>::type FIn2;
    static_assert(std::is_convertible<X, FIn0>::value,
                  "Function can not take bound parameter type");
    static_assert(std::is_convertible<Y, FIn1>::value,
                  "Function can not take provided first parameter type");
    static_assert(std::is_convertible<Z, FIn2>::value,
                  "Function can not take provided second parameter type");
};

template <typename F, typename X, typename Y, typename Z>
struct function_traits_asserts<bind_1st_and_2nd_of_3_tag, F, X, Y, Z>
{
    static_assert(utils::function_traits<F>::arity == 3,
                  "Function must take three parameters.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    typedef typename utils::function_traits<F>::template arg<1>::type FIn1;
    typedef typename utils::function_traits<F>::template arg<2>::type FIn2;
    static_assert(std::is_convertible<X, FIn0>::value,
                  "Function can not take first bound parameter type");
    static_assert(std::is_convertible<Y, FIn1>::value,
                  "Function can not take second bound parameter type");
    static_assert(std::is_convertible<Z, FIn2>::value,
                  "Function can not take provided parameter type");
};

template <typename F, typename X, typename Y, typename Z>
struct function_traits_asserts<bind_2nd_and_3rd_of_3_tag, F, X, Y, Z>
{
    static_assert(utils::function_traits<F>::arity == 3,
                  "Function must take three parameters.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    typedef typename utils::function_traits<F>::template arg<1>::type FIn1;
    typedef typename utils::function_traits<F>::template arg<2>::type FIn2;
    static_assert(std::is_convertible<X, FIn0>::value,
                  "Function can not take provided parameter type");
    static_assert(std::is_convertible<Y, FIn1>::value,
                  "Function can not take second bound parameter type");
    static_assert(std::is_convertible<Z, FIn2>::value,
                  "Function can not take first bound parameter type");
};

}
}