This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch fix_forwarding_iterators
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit e520318457b9767301116f4378500b1277884cda
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Thu Jul 8 11:55:57 2021 -0700

    no move if const_iterator
---
 common/include/conditional_forward.hpp | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/common/include/conditional_forward.hpp 
b/common/include/conditional_forward.hpp
index 4648b85..71ade84 100644
--- a/common/include/conditional_forward.hpp
+++ b/common/include/conditional_forward.hpp
@@ -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());
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to