Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

818 linhas
18KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_RANGE_FWD_HPP
  14. #define RANGES_V3_RANGE_FWD_HPP
  15. #include <type_traits>
  16. #include <utility>
  17. #include <meta/meta.hpp>
  18. #include <concepts/concepts.hpp>
  19. #include <range/v3/detail/config.hpp>
  20. #include <range/v3/utility/static_const.hpp>
  21. #include <range/v3/version.hpp>
  22. /// \defgroup group-iterator Iterator
  23. /// Iterator functionality
  24. /// \defgroup group-range Range
  25. /// Core range functionality
  26. /// \defgroup group-algorithms Algorithms
  27. /// Iterator- and range-based algorithms, like the standard algorithms
  28. /// \defgroup group-views Views
  29. /// Lazy, non-owning, non-mutating, composable range views
  30. /// \defgroup group-actions Actions
  31. /// Eager, mutating, composable algorithms
  32. /// \defgroup group-utility Utility
  33. /// Utility classes
  34. /// \defgroup group-functional Functional
  35. /// Function and function object utilities
  36. /// \defgroup group-numerics Numerics
  37. /// Numeric utilities
  38. RANGES_DIAGNOSTIC_PUSH
  39. RANGES_DIAGNOSTIC_IGNORE_CXX17_COMPAT
  40. namespace ranges
  41. {
  42. /// \cond
  43. namespace views
  44. {
  45. }
  46. namespace actions
  47. {
  48. }
  49. // GCC either fails to accept an attribute on a namespace, or else
  50. // it ignores the deprecation attribute. Frustrating.
  51. #if(RANGES_CXX_VER < RANGES_CXX_STD_17 || defined(__GNUC__) && !defined(__clang__))
  52. inline namespace v3
  53. {
  54. using namespace ranges;
  55. }
  56. namespace view = views;
  57. namespace action = actions;
  58. #else
  59. inline namespace RANGES_DEPRECATED(
  60. "The name ranges::v3 namespace is deprecated. "
  61. "Please discontinue using it.") v3
  62. {
  63. using namespace ranges;
  64. }
  65. namespace RANGES_DEPRECATED(
  66. "The ranges::view namespace has been renamed to ranges::views. "
  67. "(Sorry!)") view
  68. {
  69. using namespace views;
  70. }
  71. namespace RANGES_DEPRECATED(
  72. "The ranges::action namespace has been renamed to ranges::actions. "
  73. "(Sorry!)") action
  74. {
  75. using namespace actions;
  76. }
  77. #endif
  78. namespace _end_
  79. {
  80. struct fn;
  81. }
  82. using end_fn = _end_::fn;
  83. namespace _size_
  84. {
  85. struct fn;
  86. }
  87. template<typename>
  88. struct result_of;
  89. template<typename Sig>
  90. using result_of_t RANGES_DEPRECATED(
  91. "ranges::result_of_t is deprecated. "
  92. "Please use ranges::invoke_result_t") = meta::_t<result_of<Sig>>;
  93. /// \endcond
  94. template<typename...>
  95. struct variant;
  96. struct dangling;
  97. struct make_pipeable_fn;
  98. struct pipeable_base;
  99. template<typename First, typename Second>
  100. struct composed;
  101. template<typename... Fns>
  102. struct overloaded;
  103. namespace actions
  104. {
  105. template<typename Action>
  106. struct action;
  107. }
  108. namespace views
  109. {
  110. template<typename View>
  111. struct view;
  112. }
  113. struct advance_fn;
  114. struct advance_to_fn;
  115. struct advance_bounded_fn;
  116. struct next_fn;
  117. struct prev_fn;
  118. struct distance_fn;
  119. struct iter_size_fn;
  120. template<typename T>
  121. struct readable_traits;
  122. template<typename T>
  123. struct incrementable_traits;
  124. struct view_base
  125. {};
  126. /// \cond
  127. namespace detail
  128. {
  129. template<typename T>
  130. struct difference_type_;
  131. template<typename T>
  132. struct value_type_;
  133. } // namespace detail
  134. template<typename T>
  135. using difference_type RANGES_DEPRECATED(
  136. "ranges::difference_type<T>::type is deprecated. Use "
  137. "ranges::incrementable_traits<T>::difference_type instead.") =
  138. detail::difference_type_<T>;
  139. template<typename T>
  140. using value_type RANGES_DEPRECATED(
  141. "ranges::value_type<T>::type is deprecated. Use "
  142. "ranges::readable_traits<T>::value_type instead.") = detail::value_type_<T>;
  143. template<typename T>
  144. struct size_type;
  145. /// \endcond
  146. /// \cond
  147. namespace detail
  148. {
  149. struct ignore_t
  150. {
  151. ignore_t() = default;
  152. template<typename T>
  153. constexpr ignore_t(T &&) noexcept
  154. {}
  155. template<typename T>
  156. constexpr ignore_t const & operator=(T &&) const noexcept
  157. {
  158. return *this;
  159. }
  160. };
  161. struct value_init
  162. {
  163. template<typename T>
  164. operator T() const
  165. {
  166. return T{};
  167. }
  168. };
  169. struct make_compressed_pair_fn;
  170. template<typename T>
  171. constexpr meta::_t<std::remove_reference<T>> && move(T && t) noexcept
  172. {
  173. return static_cast<meta::_t<std::remove_reference<T>> &&>(t);
  174. }
  175. struct as_const_fn
  176. {
  177. template<typename T>
  178. constexpr T const & operator()(T & t) const noexcept
  179. {
  180. return t;
  181. }
  182. template<typename T>
  183. constexpr T const && operator()(T && t) const noexcept
  184. {
  185. return (T &&) t;
  186. }
  187. };
  188. RANGES_INLINE_VARIABLE(as_const_fn, as_const)
  189. template<typename T>
  190. using as_const_t = decltype(as_const(std::declval<T>()));
  191. template<typename T>
  192. using decay_t = meta::_t<std::decay<T>>;
  193. template<typename T, typename R = meta::_t<std::remove_reference<T>>>
  194. using as_ref_t =
  195. meta::_t<std::add_lvalue_reference<meta::_t<std::remove_const<R>>>>;
  196. template<typename T, typename R = meta::_t<std::remove_reference<T>>>
  197. using as_cref_t = meta::_t<std::add_lvalue_reference<R const>>;
  198. struct get_first;
  199. struct get_second;
  200. template<typename Val1, typename Val2>
  201. struct replacer_fn;
  202. template<typename Pred, typename Val>
  203. struct replacer_if_fn;
  204. template<typename I>
  205. struct move_into_cursor;
  206. template<typename Int>
  207. struct from_end_;
  208. template<typename... Ts>
  209. constexpr int ignore_unused(Ts &&...)
  210. {
  211. return 42;
  212. }
  213. template<int I>
  214. struct priority_tag : priority_tag<I - 1>
  215. {};
  216. template<>
  217. struct priority_tag<0>
  218. {};
  219. template<typename T>
  220. using is_trivial = meta::bool_<
  221. #if META_CXX_TRAIT_VARIABLE_TEMPLATES
  222. std::is_trivially_copyable_v<T> &&
  223. std::is_trivially_default_constructible_v<T>>;
  224. #else
  225. std::is_trivially_copyable<T>::value &&
  226. std::is_trivially_default_constructible<T>::value>;
  227. #endif
  228. #if defined(__clang__) && !defined(_LIBCPP_VERSION)
  229. template<typename T, typename... Args>
  230. using is_trivially_constructible =
  231. meta::bool_<__is_trivially_constructible(T, Args...)>;
  232. template<typename T>
  233. using is_trivially_default_constructible = is_trivially_constructible<T>;
  234. template<typename T>
  235. using is_trivially_copy_constructible = is_trivially_constructible<T, T const &>;
  236. template<typename T>
  237. using is_trivially_move_constructible = is_trivially_constructible<T, T>;
  238. template<typename T, typename U>
  239. using is_trivially_assignable = meta::bool_<__is_trivially_assignable(T, U)>;
  240. template<typename T>
  241. using is_trivially_copy_assignable = is_trivially_assignable<T &, T const &>;
  242. template<typename T>
  243. using is_trivially_move_assignable = is_trivially_assignable<T &, T>;
  244. template<typename T>
  245. using is_trivially_copyable = meta::bool_<__is_trivially_copyable(T)>;
  246. #else
  247. template<typename T>
  248. using is_trivially_default_constructible = std::is_trivially_constructible<T>;
  249. using std::is_trivially_copy_assignable;
  250. using std::is_trivially_copy_constructible;
  251. using std::is_trivially_copyable;
  252. using std::is_trivially_move_assignable;
  253. using std::is_trivially_move_constructible;
  254. #endif
  255. #if RANGES_CXX_LIB_IS_FINAL > 0
  256. #if defined(__clang__) && !defined(_LIBCPP_VERSION)
  257. template<typename T>
  258. using is_final = meta::bool_<__is_final(T)>;
  259. #else
  260. using std::is_final;
  261. #endif
  262. #else
  263. template<typename T>
  264. using is_final = std::false_type;
  265. #endif
  266. // Work around libc++'s buggy std::is_function
  267. // Function types here:
  268. template<typename T>
  269. char (&is_function_impl_(priority_tag<0>))[1];
  270. // Array types here:
  271. template<typename T, typename = decltype((*(T *)0)[0])>
  272. char (&is_function_impl_(priority_tag<1>))[2];
  273. // Anything that can be returned from a function here (including
  274. // void and reference types):
  275. template<typename T, typename = T (*)()>
  276. char (&is_function_impl_(priority_tag<2>))[3];
  277. // Classes and unions (including abstract types) here:
  278. template<typename T, typename = int T::*>
  279. char (&is_function_impl_(priority_tag<3>))[4];
  280. template<typename T>
  281. RANGES_INLINE_VAR constexpr bool is_function_v =
  282. sizeof(detail::is_function_impl_<T>(priority_tag<3>{})) == 1;
  283. template<typename T>
  284. struct remove_rvalue_reference
  285. {
  286. using type = T;
  287. };
  288. template<typename T>
  289. struct remove_rvalue_reference<T &&>
  290. {
  291. using type = T;
  292. };
  293. template<typename T>
  294. using remove_rvalue_reference_t = meta::_t<remove_rvalue_reference<T>>;
  295. // Workaround bug in the Standard Library:
  296. // From cannot be an incomplete class type despite that
  297. // is_convertible<X, Y> should be equivalent to is_convertible<X&&, Y>
  298. // in such a case.
  299. template<typename From, typename To>
  300. using is_convertible =
  301. std::is_convertible<meta::_t<std::add_rvalue_reference<From>>, To>;
  302. } // namespace detail
  303. /// \endcond
  304. struct begin_tag
  305. {};
  306. struct end_tag
  307. {};
  308. struct copy_tag
  309. {};
  310. struct move_tag
  311. {};
  312. template<typename T>
  313. using uncvref_t = meta::_t<std::remove_cv<meta::_t<std::remove_reference<T>>>>;
  314. struct not_equal_to;
  315. struct equal_to;
  316. struct less;
  317. struct identity;
  318. template<typename Pred>
  319. struct logical_negate;
  320. enum cardinality : std::ptrdiff_t
  321. {
  322. infinite = -3,
  323. unknown = -2,
  324. finite = -1
  325. };
  326. template<typename Rng, typename Void = void>
  327. struct range_cardinality;
  328. template<typename Rng>
  329. using is_finite = meta::bool_<range_cardinality<Rng>::value >= finite>;
  330. template<typename Rng>
  331. using is_infinite = meta::bool_<range_cardinality<Rng>::value == infinite>;
  332. template<typename S, typename I>
  333. RANGES_INLINE_VAR constexpr bool disable_sized_sentinel = false;
  334. template<typename Cur>
  335. struct basic_mixin;
  336. template<typename Cur>
  337. struct RANGES_EMPTY_BASES basic_iterator;
  338. template<cardinality>
  339. struct basic_view : view_base
  340. {};
  341. template<typename Derived, cardinality C = finite>
  342. struct view_facade;
  343. template<typename Derived, typename BaseRng,
  344. cardinality C = range_cardinality<BaseRng>::value>
  345. struct view_adaptor;
  346. template<typename I, typename S>
  347. struct common_iterator;
  348. /// \cond
  349. namespace detail
  350. {
  351. template<typename I>
  352. struct cpp17_iterator_cursor;
  353. template<typename I>
  354. using cpp17_iterator = basic_iterator<cpp17_iterator_cursor<I>>;
  355. } // namespace detail
  356. /// \endcond
  357. template<typename First, typename Second>
  358. struct compressed_pair;
  359. template<typename T>
  360. struct bind_element;
  361. template<typename T>
  362. using bind_element_t = meta::_t<bind_element<T>>;
  363. template<typename Derived, cardinality = finite>
  364. struct view_interface;
  365. template<typename T>
  366. struct istream_view;
  367. template<typename I, typename S = I>
  368. struct RANGES_EMPTY_BASES iterator_range;
  369. template<typename I, typename S = I>
  370. struct sized_iterator_range;
  371. template<typename T>
  372. struct reference_wrapper;
  373. // Views
  374. //
  375. template<typename Rng, typename Pred>
  376. struct RANGES_EMPTY_BASES adjacent_filter_view;
  377. namespace views
  378. {
  379. struct adjacent_filter_fn;
  380. }
  381. template<typename Rng, typename Pred>
  382. struct RANGES_EMPTY_BASES adjacent_remove_if_view;
  383. namespace views
  384. {
  385. struct adjacent_remove_if_fn;
  386. }
  387. namespace views
  388. {
  389. struct all_fn;
  390. }
  391. template<typename Rng>
  392. struct const_view;
  393. namespace views
  394. {
  395. struct const_fn;
  396. }
  397. template<typename I>
  398. struct counted_view;
  399. namespace views
  400. {
  401. struct counted_fn;
  402. }
  403. struct default_sentinel_t;
  404. template<typename I>
  405. struct move_iterator;
  406. template<typename I>
  407. using move_into_iterator = basic_iterator<detail::move_into_cursor<I>>;
  408. template<typename Rng, bool = (bool)is_infinite<Rng>()>
  409. struct RANGES_EMPTY_BASES cycled_view;
  410. namespace views
  411. {
  412. struct cycle_fn;
  413. }
  414. /// \cond
  415. namespace detail
  416. {
  417. template<typename I>
  418. struct reverse_cursor;
  419. }
  420. /// \endcond
  421. template<typename I>
  422. using reverse_iterator = basic_iterator<detail::reverse_cursor<I>>;
  423. template<typename T>
  424. struct empty_view;
  425. namespace views
  426. {
  427. struct empty_fn;
  428. }
  429. template<typename Rng, typename Fun>
  430. struct group_by_view;
  431. namespace views
  432. {
  433. struct group_by_fn;
  434. }
  435. template<typename Rng>
  436. struct indirect_view;
  437. namespace views
  438. {
  439. struct indirect_fn;
  440. }
  441. struct unreachable_sentinel_t;
  442. template<typename From, typename To = unreachable_sentinel_t>
  443. struct iota_view;
  444. template<typename From, typename To = From>
  445. struct closed_iota_view;
  446. namespace views
  447. {
  448. struct iota_fn;
  449. struct closed_iota_fn;
  450. } // namespace views
  451. template<typename Rng>
  452. struct join_view;
  453. template<typename Rng, typename ValRng>
  454. struct join_with_view;
  455. namespace views
  456. {
  457. struct join_fn;
  458. }
  459. template<typename... Rngs>
  460. struct concat_view;
  461. namespace views
  462. {
  463. struct concat_fn;
  464. }
  465. template<typename Rng, typename Fun>
  466. struct partial_sum_view;
  467. namespace views
  468. {
  469. struct partial_sum_fn;
  470. }
  471. template<typename Rng>
  472. struct move_view;
  473. namespace views
  474. {
  475. struct move_fn;
  476. }
  477. template<typename Rng>
  478. struct ref_view;
  479. namespace views
  480. {
  481. struct ref_fn;
  482. }
  483. template<typename Val>
  484. struct repeat_view;
  485. namespace views
  486. {
  487. struct repeat_fn;
  488. }
  489. template<typename Rng>
  490. struct RANGES_EMPTY_BASES reverse_view;
  491. namespace views
  492. {
  493. struct reverse_fn;
  494. }
  495. template<typename Rng>
  496. struct slice_view;
  497. namespace views
  498. {
  499. struct slice_fn;
  500. }
  501. // template<typename Rng, typename Fun>
  502. // struct split_view;
  503. // namespace views
  504. // {
  505. // struct split_fn;
  506. // }
  507. template<typename Rng>
  508. struct single_view;
  509. namespace views
  510. {
  511. struct single_fn;
  512. }
  513. template<typename Rng>
  514. struct stride_view;
  515. namespace views
  516. {
  517. struct stride_fn;
  518. }
  519. template<typename Rng>
  520. struct take_view;
  521. namespace views
  522. {
  523. struct take_fn;
  524. }
  525. /// \cond
  526. namespace detail
  527. {
  528. template<typename Rng>
  529. struct is_random_access_common_;
  530. template<typename Rng,
  531. bool IsRandomAccessCommon = is_random_access_common_<Rng>::value>
  532. struct take_exactly_view_;
  533. } // namespace detail
  534. /// \endcond
  535. template<typename Rng>
  536. using take_exactly_view = detail::take_exactly_view_<Rng>;
  537. namespace views
  538. {
  539. struct take_exactly_fn;
  540. }
  541. template<typename Rng, typename Pred>
  542. struct iter_take_while_view;
  543. template<typename Rng, typename Pred>
  544. struct take_while_view;
  545. namespace views
  546. {
  547. struct iter_take_while_fn;
  548. struct take_while_fn;
  549. } // namespace views
  550. template<typename Rng, typename Regex, typename SubMatchRange>
  551. struct tokenize_view;
  552. namespace views
  553. {
  554. struct tokenize_fn;
  555. }
  556. template<typename Rng, typename Fun>
  557. struct iter_transform_view;
  558. template<typename Rng, typename Fun>
  559. struct transform_view;
  560. namespace views
  561. {
  562. struct transform_fn;
  563. }
  564. template<typename Rng, typename Val1, typename Val2>
  565. using replace_view = iter_transform_view<Rng, detail::replacer_fn<Val1, Val2>>;
  566. template<typename Rng, typename Pred, typename Val>
  567. using replace_if_view = iter_transform_view<Rng, detail::replacer_if_fn<Pred, Val>>;
  568. namespace views
  569. {
  570. struct replace_fn;
  571. struct replace_if_fn;
  572. } // namespace views
  573. template<typename Rng, typename Pred>
  574. struct trim_view;
  575. namespace views
  576. {
  577. struct trim_fn;
  578. }
  579. template<typename I>
  580. struct unbounded_view;
  581. namespace views
  582. {
  583. struct unbounded_fn;
  584. }
  585. template<typename Rng>
  586. using unique_view = adjacent_filter_view<Rng, logical_negate<equal_to>>;
  587. namespace views
  588. {
  589. struct unique_fn;
  590. }
  591. template<typename Rng>
  592. using keys_range_view = transform_view<Rng, detail::get_first>;
  593. template<typename Rng>
  594. using values_view = transform_view<Rng, detail::get_second>;
  595. namespace views
  596. {
  597. struct keys_fn;
  598. struct values_fn;
  599. } // namespace views
  600. template<typename Fun, typename... Rngs>
  601. struct iter_zip_with_view;
  602. template<typename Fun, typename... Rngs>
  603. struct zip_with_view;
  604. template<typename... Rngs>
  605. struct zip_view;
  606. namespace views
  607. {
  608. struct iter_zip_with_fn;
  609. struct zip_with_fn;
  610. struct zip_fn;
  611. } // namespace views
  612. } // namespace ranges
  613. namespace ranges
  614. {
  615. namespace concepts = ::concepts;
  616. using namespace ::concepts::defs;
  617. using ::concepts::and_v;
  618. // namespace lazy
  619. // {
  620. // using namespace ::concepts::defs::lazy;
  621. // }
  622. namespace defer
  623. {
  624. using namespace ::concepts::defs::defer;
  625. }
  626. } // namespace ranges
  627. RANGES_DIAGNOSTIC_POP
  628. /// \endcond
  629. #endif