Skip to content
Permalink
Browse files
no move if const_iterator
  • Loading branch information
AlexanderSaydakov committed Jul 8, 2021
1 parent dc24f84 commit e520318457b9767301116f4378500b1277884cda
Showing 1 changed file with 20 additions and 8 deletions.
@@ -38,29 +38,41 @@ fwd_type<T1, T2> conditional_forward(T2&& value) {
// Forward container as iterators

template<typename Container>
auto forward_begin(Container&& c) ->
typename std::enable_if<std::is_lvalue_reference<Container>::value, decltype(c.begin())>::type
auto forward_begin(Container&& c) -> typename std::enable_if<
std::is_lvalue_reference<Container>::value ||
std::is_same<typename std::remove_reference<Container>::type::const_iterator, decltype(c.begin())>::value,
decltype(c.begin())
>::type
{
return c.begin();
}

template<typename Container>
auto forward_begin(Container&& c) ->
typename std::enable_if<!std::is_lvalue_reference<Container>::value, decltype(std::make_move_iterator(c.begin()))>::type
auto forward_begin(Container&& c) -> typename std::enable_if<
!std::is_lvalue_reference<Container>::value &&
!std::is_same<typename std::remove_reference<Container>::type::const_iterator, decltype(c.begin())>::value,
decltype(std::make_move_iterator(c.begin()))
>::type
{
return std::make_move_iterator(c.begin());
}

template<typename Container>
auto forward_end(Container&& c) ->
typename std::enable_if<std::is_lvalue_reference<Container>::value, decltype(c.end())>::type
auto forward_end(Container&& c) -> typename std::enable_if<
std::is_lvalue_reference<Container>::value ||
std::is_same<typename std::remove_reference<Container>::type::const_iterator, decltype(c.begin())>::value,
decltype(c.end())
>::type
{
return c.end();
}

template<typename Container>
auto forward_end(Container&& c) ->
typename std::enable_if<!std::is_lvalue_reference<Container>::value, decltype(std::make_move_iterator(c.end()))>::type
auto forward_end(Container&& c) -> typename std::enable_if<
!std::is_lvalue_reference<Container>::value &&
!std::is_same<typename std::remove_reference<Container>::type::const_iterator, decltype(c.begin())>::value,
decltype(std::make_move_iterator(c.end()))
>::type
{
return std::make_move_iterator(c.end());
}

0 comments on commit e520318

Please sign in to comment.