回答編集履歴
4
m
test
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
```cpp
|
10
|
+
|
11
|
+
namespace inferior{
|
10
12
|
|
11
13
|
template<bool b>
|
12
14
|
|
@@ -54,6 +56,8 @@
|
|
54
56
|
|
55
57
|
>;
|
56
58
|
|
59
|
+
}
|
60
|
+
|
57
61
|
```
|
58
62
|
|
59
63
|
|
3
mi
test
CHANGED
@@ -15,20 +15,6 @@
|
|
15
15
|
template<bool b>
|
16
16
|
|
17
17
|
using bool_constant = std::integral_constant<bool, b>;
|
18
|
-
|
19
|
-
template<typename...> struct conjunction : std::true_type {};
|
20
|
-
|
21
|
-
template<typename B1> struct conjunction<B1> : B1 {};
|
22
|
-
|
23
|
-
template<typename B1, typename... Bn>
|
24
|
-
|
25
|
-
struct conjunction<B1, Bn...>
|
26
|
-
|
27
|
-
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
|
28
|
-
|
29
|
-
template<typename B>
|
30
|
-
|
31
|
-
struct negation : bool_constant<!bool(B::value)> {};
|
32
18
|
|
33
19
|
template<typename...>
|
34
20
|
|
2
l
test
CHANGED
@@ -77,3 +77,5 @@
|
|
77
77
|
|
78
78
|
|
79
79
|
msvc: [https://github.com/microsoft/STL/blob/ac4fde764ae716512bdd67e0e9577bd53947bc3d/stl/inc/vector#L507-L508](https://github.com/microsoft/STL/blob/ac4fde764ae716512bdd67e0e9577bd53947bc3d/stl/inc/vector#L507-L508)
|
80
|
+
|
81
|
+
libstdc++: [https://github.com/gcc-mirror/gcc/blob/d61d2a5f3ce9238bad7cbd7733d90c6ec7ae5fbc/libstdc%2B%2B-v3/include/bits/stl_vector.h#L651-L654](https://github.com/gcc-mirror/gcc/blob/d61d2a5f3ce9238bad7cbd7733d90c6ec7ae5fbc/libstdc%2B%2B-v3/include/bits/stl_vector.h#L651-L654)
|
1
e
test
CHANGED
@@ -2,4 +2,78 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
イメージとしてはこんなのを作ります。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```cpp
|
10
|
+
|
11
|
+
template<bool b>
|
12
|
+
|
13
|
+
using enable_if_t = typename std::enable_if<b, std::nullptr_t>::type;
|
14
|
+
|
15
|
+
template<bool b>
|
16
|
+
|
17
|
+
using bool_constant = std::integral_constant<bool, b>;
|
18
|
+
|
19
|
+
template<typename...> struct conjunction : std::true_type {};
|
20
|
+
|
21
|
+
template<typename B1> struct conjunction<B1> : B1 {};
|
22
|
+
|
23
|
+
template<typename B1, typename... Bn>
|
24
|
+
|
25
|
+
struct conjunction<B1, Bn...>
|
26
|
+
|
27
|
+
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
|
28
|
+
|
29
|
+
template<typename B>
|
30
|
+
|
31
|
+
struct negation : bool_constant<!bool(B::value)> {};
|
32
|
+
|
33
|
+
template<typename...>
|
34
|
+
|
35
|
+
using void_t = void;
|
36
|
+
|
37
|
+
template<typename T, typename = void>
|
38
|
+
|
39
|
+
struct is_iterator : std::false_type {};
|
40
|
+
|
41
|
+
template<typename T>
|
42
|
+
|
43
|
+
struct is_iterator<T, void_t<typename std::iterator_traits<T>::iterator_category>>
|
44
|
+
|
45
|
+
: std::true_type
|
46
|
+
|
47
|
+
{};
|
48
|
+
|
49
|
+
template<typename Iterator, bool is_iterator = is_iterator<Iterator>::value>
|
50
|
+
|
51
|
+
struct is_input_iterator : std::false_type {};
|
52
|
+
|
53
|
+
template<typename Iterator>
|
54
|
+
|
55
|
+
struct is_input_iterator<Iterator, true> : std::is_base_of<
|
56
|
+
|
57
|
+
std::input_iterator_tag,
|
58
|
+
|
59
|
+
typename std::iterator_traits<Iterator>::iterator_category
|
60
|
+
|
61
|
+
> {};
|
62
|
+
|
63
|
+
template<typename InputIter>
|
64
|
+
|
65
|
+
using require_input_iterator = enable_if_t<
|
66
|
+
|
67
|
+
inferior::is_input_iterator<InputIter>::value
|
68
|
+
|
69
|
+
>;
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
実際のSTLの実装を見てみてもそうなっていますね。
|
76
|
+
|
77
|
+
|
78
|
+
|
5
79
|
msvc: [https://github.com/microsoft/STL/blob/ac4fde764ae716512bdd67e0e9577bd53947bc3d/stl/inc/vector#L507-L508](https://github.com/microsoft/STL/blob/ac4fde764ae716512bdd67e0e9577bd53947bc3d/stl/inc/vector#L507-L508)
|