Skip to content

Commit

Permalink
no move if const_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSaydakov committed Jul 9, 2021
1 parent 168c242 commit a375f98
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions common/include/conditional_forward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit a375f98

Please sign in to comment.