9 #ifndef COVEO_SEQUENCE_UTIL_H 10 #define COVEO_SEQUENCE_UTIL_H 12 #include <coveo/seq/detail/enumerable_detail.h> 17 #include <type_traits> 54 using const_value_type =
const value_type;
61 using raw_value_type =
typename std::remove_cv<value_type>::type;
69 using pointer = value_type*;
77 using reference = value_type&;
85 using const_pointer = const_value_type*;
93 using const_reference = const_value_type&;
112 template<
typename Seq>
121 using iterator_type =
typename std::decay<
decltype(std::begin(std::declval<Seq&>()))>::type;
129 #ifdef DOXYGEN_INVOKED 138 template<
typename T>
struct is_enumerable;
140 template<
typename>
struct is_enumerable : std::false_type { };
141 template<
typename T>
struct is_enumerable<
enumerable<T>> : std::true_type { };
165 template<
typename C,
typename Seq>
168 const bool can_reserve = seq.has_fast_size();
170 cnt.reserve(seq.size());
174 template<
typename C,
typename Seq>
175 auto try_reserve(C& cnt,
const Seq& seq) ->
typename std::enable_if<!is_enumerable<Seq>::value &&
176 coveo::detail::has_size_const_method<Seq>::value,
bool>::type
178 cnt.reserve(seq.size());
181 template<
typename C,
typename Seq>
182 auto try_reserve(C& cnt,
const Seq& seq) ->
typename std::enable_if<!coveo::detail::has_size_const_method<Seq>::value &&
183 std::is_base_of<std::random_access_iterator_tag,
184 typename std::iterator_traits<
typename seq_traits<Seq>::iterator_type>::iterator_category>::value,
187 cnt.reserve(std::distance(std::begin(seq), std::end(seq)));
190 template<
typename C,
typename Seq>
191 auto try_reserve(C&,
const Seq&) ->
typename std::enable_if<!coveo::detail::has_size_const_method<
typename std::decay<Seq>::type>::value &&
192 !std::is_base_of<std::random_access_iterator_tag,
193 typename std::iterator_traits<
typename seq_traits<Seq>::iterator_type>::iterator_category>::value,
226 template<
typename Seq>
228 std::function<std::size_t()>>::
type 230 std::function<std::size_t()> siz;
231 if (seq.has_fast_size()) {
232 const std::size_t size = seq.size();
233 siz = [size]() -> std::size_t {
return size; };
237 template<
typename Seq>
238 auto try_get_size_delegate(
const Seq& seq) ->
typename std::enable_if<!is_enumerable<Seq>::value &&
239 coveo::detail::has_size_const_method<Seq>::value,
240 std::function<std::size_t()>>::type
242 const std::size_t size = seq.size();
243 return [size]() -> std::size_t {
return size; };
245 template<
typename Seq>
246 auto try_get_size_delegate(
const Seq& seq) ->
typename std::enable_if<!coveo::detail::has_size_const_method<Seq>::value &&
247 std::is_base_of<std::random_access_iterator_tag,
248 typename std::iterator_traits<
typename seq_traits<Seq>::iterator_type>::iterator_category>::value,
249 std::function<std::size_t()>>::type
251 const std::size_t size =
static_cast<std::size_t>(std::distance(std::begin(seq), std::end(seq)));
252 return [size]() -> std::size_t {
return size; };
254 template<
typename Seq>
255 auto try_get_size_delegate(
const Seq&) ->
typename std::enable_if<!coveo::detail::has_size_const_method<Seq>::value &&
256 !std::is_base_of<std::random_access_iterator_tag,
257 typename std::iterator_traits<
typename seq_traits<Seq>::iterator_type>::iterator_category>::value,
258 std::function<std::size_t()>>::type
284 template<
typename It>
286 typename std::iterator_traits<It>::iterator_category>::value,
287 std::function<std::size_t()>>::
type 289 return [beg, end]() -> std::size_t {
return std::distance(beg, end); };
291 template<
typename It>
292 auto try_get_size_delegate_for_iterators(
const It&,
const It&) ->
typename std::enable_if<!std::is_base_of<std::random_access_iterator_tag,
293 typename std::iterator_traits<It>::iterator_category>::value,
294 std::function<std::size_t()>>::type
auto try_reserve(C &cnt, const Seq &seq) -> typename std::enable_if< is_enumerable< Seq >::value, bool >::type
Helper function to quickly reserve space in a container if possible.
Definition: sequence_util.h:166
auto try_get_size_delegate_for_iterators(const It &beg, const It &end) -> typename std::enable_if< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< It >::iterator_category >::value, std::function< std::size_t()>>::type
Helper function to get a fast size delegate from iterators if possible.
Definition: sequence_util.h:285
Traits class for a sequence.
Definition: sequence_util.h:113
Type-erased sequence wrapper.
Definition: enumerable.h:62
Traits class for elements in a sequence.
Definition: sequence_util.h:40
auto try_get_size_delegate(const Seq &seq) -> typename std::enable_if< is_enumerable< Seq >::value, std::function< std::size_t()>>::type
Helper function to get a fast size delegate if possible.
Definition: sequence_util.h:227