Skip to content

Instantly share code, notes, and snippets.

@rbock
Created September 2, 2017 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbock/74b5bb732bb1049c2ec901c82606e737 to your computer and use it in GitHub Desktop.
Save rbock/74b5bb732bb1049c2ec901c82606e737 to your computer and use it in GitHub Desktop.
#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