-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathsorter_facade_fptr.cpp
99 lines (88 loc) · 3.32 KB
/
sorter_facade_fptr.cpp
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
/*
* Copyright (c) 2021-2022 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <functional>
#include <type_traits>
#include <vector>
#include <catch2/catch_test_macros.hpp>
#include <cpp-sort/sorter_facade.h>
#include <cpp-sort/sorter_traits.h>
#include <cpp-sort/utility/functional.h>
namespace
{
struct dummy_t {};
struct sorter_impl
{
template<
typename Iterator,
typename Compare = std::less<>,
typename Projection = cppsort::utility::identity,
typename = std::enable_if_t<cppsort::is_projection_iterator_v<
Projection, Iterator, Compare
>>
>
auto operator()(Iterator, Iterator, Compare={}, Projection={}) const
-> dummy_t
{
return {};
}
};
struct sorter:
cppsort::sorter_facade<sorter_impl>
{};
}
TEST_CASE( "check conversions from sorter_facade to fptr",
"[sorter_facade][function_pointer]" )
{
// Collection to "sort"
std::vector<int> vec;
sorter sort_it;
// The tests in this section are just compilation tests
SECTION( "conversion to function pointer" )
{
constexpr dummy_t(*sort1)(std::vector<int>&) = sort_it;
constexpr dummy_t(*sort2)(std::vector<int>&, std::greater<>) = sort_it;
constexpr dummy_t(*sort3)(std::vector<int>&, std::negate<>) = sort_it;
constexpr dummy_t(*sort4)(std::vector<int>&, std::greater<>, std::negate<>) = sort_it;
constexpr dummy_t(*sort5)(std::vector<int>::iterator, std::vector<int>::iterator) = sort_it;
constexpr dummy_t(*sort6)(std::vector<int>::iterator, std::vector<int>::iterator,
std::greater<>) = sort_it;
constexpr dummy_t(*sort7)(std::vector<int>::iterator, std::vector<int>::iterator,
std::negate<>) = sort_it;
constexpr dummy_t(*sort8)(std::vector<int>::iterator, std::vector<int>::iterator,
std::greater<>, std::negate<>) = sort_it;
(void)sort1;
(void)sort2;
(void)sort3;
(void)sort4;
(void)sort5;
(void)sort6;
(void)sort7;
(void)sort8;
CHECK( true );
}
SECTION( "conversion to function pointer with void return type" )
{
constexpr void(*sort1)(std::vector<int>&) = sort_it;
constexpr void(*sort2)(std::vector<int>&, std::greater<>) = sort_it;
constexpr void(*sort3)(std::vector<int>&, std::negate<>) = sort_it;
constexpr void(*sort4)(std::vector<int>&, std::greater<>, std::negate<>) = sort_it;
constexpr void(*sort5)(std::vector<int>::iterator, std::vector<int>::iterator) = sort_it;
constexpr void(*sort6)(std::vector<int>::iterator, std::vector<int>::iterator,
std::greater<>) = sort_it;
constexpr void(*sort7)(std::vector<int>::iterator, std::vector<int>::iterator,
std::negate<>) = sort_it;
constexpr void(*sort8)(std::vector<int>::iterator, std::vector<int>::iterator,
std::greater<>, std::negate<>) = sort_it;
(void)sort1;
(void)sort2;
(void)sort3;
(void)sort4;
(void)sort5;
(void)sort6;
(void)sort7;
(void)sort8;
CHECK( true );
}
}