Skip to content

Instantly share code, notes, and snippets.

@orlp
Created December 19, 2014 19:56
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 orlp/41dbdbc0871bf4aa672e to your computer and use it in GitHub Desktop.
Save orlp/41dbdbc0871bf4aa672e to your computer and use it in GitHub Desktop.
#include <iterator>
#include <type_traits>
template<class Iterator>
using move_if_noexcept_iterator = typename std::conditional<
!std::is_nothrow_move_constructible<
typename std::iterator_traits<Iterator>::value_type
>::value && std::is_copy_constructible<
typename std::iterator_traits<Iterator>::value_type
>::value,
Iterator,
std::move_iterator<Iterator>
>::type;
template<class Iterator>
constexpr move_if_noexcept_iterator<Iterator> make_move_if_noexcept_iterator(Iterator i) {
return move_if_noexcept_iterator<Iterator>(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment