回答編集履歴
4
m
answer
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
イメージとしてはこんなのを作ります。
|
4
4
|
|
5
5
|
```cpp
|
6
|
+
namespace inferior{
|
6
7
|
template<bool b>
|
7
8
|
using enable_if_t = typename std::enable_if<b, std::nullptr_t>::type;
|
8
9
|
template<bool b>
|
@@ -26,6 +27,7 @@
|
|
26
27
|
using require_input_iterator = enable_if_t<
|
27
28
|
inferior::is_input_iterator<InputIter>::value
|
28
29
|
>;
|
30
|
+
}
|
29
31
|
```
|
30
32
|
|
31
33
|
実際のSTLの実装を見てみてもそうなっていますね。
|
3
mi
answer
CHANGED
@@ -7,13 +7,6 @@
|
|
7
7
|
using enable_if_t = typename std::enable_if<b, std::nullptr_t>::type;
|
8
8
|
template<bool b>
|
9
9
|
using bool_constant = std::integral_constant<bool, b>;
|
10
|
-
template<typename...> struct conjunction : std::true_type {};
|
11
|
-
template<typename B1> struct conjunction<B1> : B1 {};
|
12
|
-
template<typename B1, typename... Bn>
|
13
|
-
struct conjunction<B1, Bn...>
|
14
|
-
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
|
15
|
-
template<typename B>
|
16
|
-
struct negation : bool_constant<!bool(B::value)> {};
|
17
10
|
template<typename...>
|
18
11
|
using void_t = void;
|
19
12
|
template<typename T, typename = void>
|
2
l
answer
CHANGED
@@ -37,4 +37,5 @@
|
|
37
37
|
|
38
38
|
実際のSTLの実装を見てみてもそうなっていますね。
|
39
39
|
|
40
|
-
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)
|
40
|
+
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)
|
41
|
+
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
answer
CHANGED
@@ -1,3 +1,40 @@
|
|
1
1
|
SFINAEでイテレーターであることを確認していると思います。
|
2
2
|
|
3
|
+
イメージとしてはこんなのを作ります。
|
4
|
+
|
5
|
+
```cpp
|
6
|
+
template<bool b>
|
7
|
+
using enable_if_t = typename std::enable_if<b, std::nullptr_t>::type;
|
8
|
+
template<bool b>
|
9
|
+
using bool_constant = std::integral_constant<bool, b>;
|
10
|
+
template<typename...> struct conjunction : std::true_type {};
|
11
|
+
template<typename B1> struct conjunction<B1> : B1 {};
|
12
|
+
template<typename B1, typename... Bn>
|
13
|
+
struct conjunction<B1, Bn...>
|
14
|
+
: std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
|
15
|
+
template<typename B>
|
16
|
+
struct negation : bool_constant<!bool(B::value)> {};
|
17
|
+
template<typename...>
|
18
|
+
using void_t = void;
|
19
|
+
template<typename T, typename = void>
|
20
|
+
struct is_iterator : std::false_type {};
|
21
|
+
template<typename T>
|
22
|
+
struct is_iterator<T, void_t<typename std::iterator_traits<T>::iterator_category>>
|
23
|
+
: std::true_type
|
24
|
+
{};
|
25
|
+
template<typename Iterator, bool is_iterator = is_iterator<Iterator>::value>
|
26
|
+
struct is_input_iterator : std::false_type {};
|
27
|
+
template<typename Iterator>
|
28
|
+
struct is_input_iterator<Iterator, true> : std::is_base_of<
|
29
|
+
std::input_iterator_tag,
|
30
|
+
typename std::iterator_traits<Iterator>::iterator_category
|
31
|
+
> {};
|
32
|
+
template<typename InputIter>
|
33
|
+
using require_input_iterator = enable_if_t<
|
34
|
+
inferior::is_input_iterator<InputIter>::value
|
35
|
+
>;
|
36
|
+
```
|
37
|
+
|
38
|
+
実際のSTLの実装を見てみてもそうなっていますね。
|
39
|
+
|
3
40
|
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)
|