File: pairs.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 (114 lines) | stat: -rw-r--r-- 4,167 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
112
113
114
// 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 apply_to_pair_tag
{
};

struct zip_with_tag
{
};

struct zip_with_3_tag
{
};

struct transform_fst_tag
{
};

struct transform_snd_tag
{
};

struct inner_product_with_tag
{
};

template <typename F, typename X, typename Y>
struct function_traits_asserts<apply_to_pair_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 does not take pair.first type as first Parameter.");
    static_assert(std::is_convertible<Y, FIn1>::value,
        "Function does not take pair.second type as second Parameter.");
};

template <typename F, typename X, typename Y>
struct function_traits_asserts<zip_with_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 does not take elements from first Container as first Parameter.");
    static_assert(std::is_convertible<Y, FIn1>::value,
        "Function does not take elements from second Container as second Parameter.");
};

template <typename F, typename X, typename Y, typename Z>
struct function_traits_asserts<zip_with_3_tag, F, X, Y, Z>
{
    static_assert(utils::function_traits<F>::arity == 3,
        "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;
    typedef typename utils::function_traits<F>::template arg<2>::type FIn2;
    static_assert(std::is_convertible<X, FIn0>::value,
        "Function does not take elements from first Container as first Parameter.");
    static_assert(std::is_convertible<Y, FIn1>::value,
        "Function does not take elements from second Container as second Parameter.");
    static_assert(std::is_convertible<Z, FIn2>::value,
        "Function does not take elements from third Container as third Parameter.");
};

template <typename F, typename X>
struct function_traits_asserts<transform_fst_tag, F, X>
{
    static_assert(utils::function_traits<F>::arity == 1,
        "Function must take one parameter.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    static_assert(std::is_convertible<X, FIn0>::value,
        "Function does not take pair.first type as first Parameter.");
};

template <typename F, typename X>
struct function_traits_asserts<transform_snd_tag, F, X>
{
    static_assert(utils::function_traits<F>::arity == 1,
        "Function must take one parameter.");
    typedef typename utils::function_traits<F>::template arg<0>::type FIn0;
    static_assert(std::is_convertible<X, FIn0>::value,
        "Function does not take pair.second type as first Parameter.");
};

template <typename F, typename X, typename Y>
struct function_traits_asserts<inner_product_with_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 does not take elements from first Container as first Parameter.");
    static_assert(std::is_convertible<Y, FIn1>::value,
        "Function does not take elements from second Container as second Parameter.");
};
}
}