Created
September 2, 2017 15:50
-
-
Save rbock/74b5bb732bb1049c2ec901c82606e737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <iostream> | |
using namespace std; | |
template <typename Iterator> | |
using value_type = typename Iterator::value_type; | |
template <typename Iterator, typename Data> | |
auto copy_or_move(Iterator begin, Iterator end, Data& new_memory) | |
-> enable_if_t< ! is_nothrow_move_constructible<value_type<Iterator>>::value> | |
{ | |
std::cout << "copy" << std::endl; | |
} | |
template <typename Iterator, typename Data> | |
auto copy_or_move(Iterator begin, Iterator end, Data& new_memory) | |
-> enable_if_t<is_nothrow_move_constructible<value_type<Iterator>>::value> | |
{ | |
std::cout << "move" << std::endl; | |
} | |
struct A | |
{ | |
A(A&&); | |
}; | |
struct B | |
{ | |
B(B&&) noexcept; | |
}; | |
template<typename T> | |
struct I | |
{ | |
using value_type = T; | |
}; | |
int main() | |
{ | |
auto ia = I<A>{}; | |
copy_or_move(ia, ia, std::cout); | |
auto ib = I<B>{}; | |
copy_or_move(ib, ib, std::cout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment