/usr/include/range/v3/utility/functional.hpp is in librange-v3-dev 0.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_UTILITY_FUNCTIONAL_HPP
#define RANGES_V3_UTILITY_FUNCTIONAL_HPP
#include <memory> // std::addressof
#include <utility>
#include <functional> // std::reference_wrapper
#include <type_traits>
#include <initializer_list>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/utility/box.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/concepts.hpp>
#include <range/v3/utility/invoke.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/compressed_pair.hpp>
RANGES_DISABLE_WARNINGS
namespace ranges
{
inline namespace v3
{
/// \addtogroup group-utility
/// @{
struct equal_to
{
template<typename T, typename U,
CONCEPT_REQUIRES_(EqualityComparable<T, U>())>
constexpr bool operator()(T && t, U && u) const
{
return (T &&) t == (U &&) u;
}
using is_transparent = void;
};
struct not_equal_to
{
template<typename T, typename U,
CONCEPT_REQUIRES_(EqualityComparable<T, U>())>
constexpr bool operator()(T && t, U && u) const
{
return (T &&) t != (U &&) u;
}
using is_transparent = void;
};
struct less
{
template<typename T, typename U,
CONCEPT_REQUIRES_(WeaklyOrdered<T, U>())>
constexpr bool operator()(T && t, U && u) const
{
return (T &&) t < (U &&) u;
}
using is_transparent = void;
};
struct ordered_less
{
template<typename T, typename U,
CONCEPT_REQUIRES_(TotallyOrdered<T, U>())>
constexpr bool operator()(T && t, U && u) const
{
return (T &&) t < (U &&) u;
}
using is_transparent = void;
};
struct ident
{
template<typename T>
constexpr
T && operator()(T && t) const noexcept
{
return (T &&) t;
}
using is_transparent = void;
};
struct plus
{
template<typename T, typename U>
constexpr
auto operator()(T && t, U && u) const ->
decltype((T &&) t + (U &&) u)
{
return (T &&) t + (U &&) u;
}
using is_transparent = void;
};
struct minus
{
template<typename T, typename U>
constexpr
auto operator()(T && t, U && u) const ->
decltype((T &&) t - (U &&) u)
{
return (T &&) t - (U &&) u;
}
using is_transparent = void;
};
struct multiplies
{
template<typename T, typename U>
constexpr
auto operator()(T && t, U && u) const ->
decltype((T &&) t * (U &&) u)
{
return (T &&) t * (U &&) u;
}
using is_transparent = void;
};
struct bitwise_or
{
template<typename T, typename U>
constexpr
auto operator()(T && t, U && u) const ->
decltype((T &&) t | (U &&) u)
{
return (T &&) t | (U &&) u;
}
using is_transparent = void;
};
template<typename T>
struct convert_to
{
template<typename U>
constexpr auto operator()(U && u) const
RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
(
static_cast<T>((U &&) u)
)
};
template<typename T>
struct coerce
{
constexpr
T & operator()(T & t) const
{
return t;
}
/// \overload
constexpr
T const & operator()(T const & t) const
{
return t;
}
/// \overload
constexpr
T operator()(T && t) const
{
return (T &&) t;
}
T operator()(T const &&) const = delete;
};
template<typename T>
struct coerce<T const>
: coerce<T>
{};
template<typename T>
struct coerce<T &>
: coerce<T>
{};
template<typename T>
struct coerce<T &&>
: coerce<T>
{};
struct dereference_fn
{
template<typename I>
constexpr auto operator()(I &i) const
RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
(
*i
)
};
RANGES_INLINE_VARIABLE(dereference_fn, dereference)
/// \addtogroup group-concepts
/// @{
namespace concepts
{
struct Invocable
{
template<typename Fun, typename... Args>
using result_t = result_of_t<Fun &&(Args &&...)>;
template<typename Fun, typename... Args>
auto requires_() ->
meta::void_<result_of_t<Fun &&(Args &&...)>>;
};
struct RegularInvocable
: refines<Invocable>
{
// Axiom: equality_preserving(invoke(f, args...))
};
struct Predicate
: refines<RegularInvocable>
{
template<typename Fun, typename... Args>
auto requires_() -> decltype(
concepts::valid_expr(
concepts::model_of<ConvertibleTo, Invocable::result_t<Fun, Args...>, bool>()
));
};
struct Relation
{
template<typename Fun, typename T>
auto requires_() -> decltype(
concepts::valid_expr(
concepts::model_of<Predicate, Fun, T, T>()
));
template<typename Fun, typename T, typename U>
auto requires_() -> decltype(
concepts::valid_expr(
concepts::is_true(std::is_same<T, U>{}),
concepts::model_of<Predicate, Fun, T, U>()
));
template<typename Fun, typename T, typename U,
typename C =
common_reference_t<detail::as_cref_t<T>, detail::as_cref_t<U>>>
auto requires_() -> decltype(
concepts::valid_expr(
concepts::is_false(std::is_same<T, U>{}),
concepts::model_of<Relation, Fun, T, T>(),
concepts::model_of<Relation, Fun, U, U>(),
concepts::model_of<
CommonReference, detail::as_cref_t<T>, detail::as_cref_t<U>>(),
concepts::model_of<Relation, Fun, C, C>(),
concepts::model_of<Predicate, Fun, T, U>(),
concepts::model_of<Predicate, Fun, U, T>()
));
};
}
template<typename Fun, typename...Args>
using Invocable = concepts::models<concepts::Invocable, Fun, Args...>;
template<typename Fun, typename...Args>
using RegularInvocable = concepts::models<concepts::RegularInvocable, Fun, Args...>;
template<typename Fun, typename...Args>
using Predicate = concepts::models<concepts::Predicate, Fun, Args...>;
template<typename Fun, typename T, typename U = T>
using Relation = concepts::models<concepts::Relation, Fun, T, U>;
/// @}
template<typename FD>
struct logical_negate_
{
private:
CONCEPT_ASSERT(Same<FD, detail::decay_t<FD>>() && MoveConstructible<FD>());
FD pred_;
public:
CONCEPT_REQUIRES(DefaultConstructible<FD>())
constexpr logical_negate_()
noexcept(std::is_nothrow_default_constructible<FD>::value)
{}
template<typename T,
typename U = meta::if_c<!Same<detail::decay_t<T>, logical_negate_>(), T>,
CONCEPT_REQUIRES_(Constructible<FD, U>())>
explicit constexpr logical_negate_(T && pred)
: pred_(static_cast<T &&>(pred))
{}
// HACKHACKHACK GCC 4.8 is extremely confused about && and const&& qualifiers.
// Luckily they are rare - we'll simply break them.
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 && __GNUC_MINOR__ < 9
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD &, Args...>())>
RANGES_CXX14_CONSTEXPR auto operator()(Args &&...args)
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD &>(), static_cast<Args &&>(args)...))
{
return !invoke(pred_, static_cast<Args &&>(args)...);
}
/// \overload
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD const &, Args...>())>
constexpr auto operator()(Args &&...args) const
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD const &>(), static_cast<Args &&>(args)...))
{
return !invoke(pred_, static_cast<Args &&>(args)...);
}
#else // ^^^ GCC <= 4.8 / GCC > 4.8 vvvv
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD &, Args...>())>
RANGES_CXX14_CONSTEXPR auto operator()(Args &&...args) &
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD &>(), static_cast<Args &&>(args)...))
{
return !invoke(pred_, static_cast<Args &&>(args)...);
}
/// \overload
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD const &, Args...>())>
constexpr auto operator()(Args &&...args) const &
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD const &>(), static_cast<Args &&>(args)...))
{
return !invoke(pred_, static_cast<Args &&>(args)...);
}
/// \overload
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD, Args...>())>
RANGES_CXX14_CONSTEXPR auto operator()(Args &&...args) &&
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD>(), static_cast<Args &&>(args)...))
{
return !invoke(static_cast<FD &&>(pred_), static_cast<Args &&>(args)...);
}
/// \overload
template<typename ...Args,
CONCEPT_REQUIRES_(Predicate<FD const, Args...>())>
RANGES_CXX14_CONSTEXPR auto operator()(Args &&...args) const &&
RANGES_DECLTYPE_NOEXCEPT(
!invoke(std::declval<FD const>(), static_cast<Args &&>(args)...))
{
return !invoke(static_cast<FD const &&>(pred_), static_cast<Args &&>(args)...);
}
#endif // GCC
};
template<typename Pred>
using logical_negate = logical_negate_<detail::decay_t<Pred>>;
struct not_fn_fn
{
template<typename Pred, typename FD = detail::decay_t<Pred>,
CONCEPT_REQUIRES_(MoveConstructible<FD>() && Constructible<FD, Pred>())>
constexpr logical_negate_<FD> operator()(Pred && pred) const
{
return logical_negate_<FD>{(Pred &&) pred};
}
};
/// \ingroup group-utility
/// \sa `not_fn_fn`
RANGES_INLINE_VARIABLE(not_fn_fn, not_fn)
/// \cond
inline namespace
{
RANGES_DEPRECATED("\"not_\" now uses the C++17 name \"not_fn\".")
constexpr const auto& not_ = not_fn;
}
/// \endcond
template<typename Second, typename First>
struct composed
: private compressed_pair<First, Second>
{
private:
using composed::compressed_pair::first;
using composed::compressed_pair::second;
template<typename A, typename B, typename...Ts>
static auto do_(A &a, B &b, std::false_type, Ts &&...ts)
RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
(
invoke(b, invoke(a, (Ts &&) ts...))
)
template<typename A, typename B, typename...Ts>
static auto do_(A &a, B &b, std::true_type, Ts &&...ts)
RANGES_DECLTYPE_AUTO_RETURN_NOEXCEPT
(
(invoke(a, (Ts &&) ts...),
invoke(b))
)
public:
composed() = default;
composed(Second second, First first)
: composed::compressed_pair{std::move(first), std::move(second)}
{}
template<typename...Ts,
typename FirstResultT = result_of_t<First&(Ts &&...)>>
auto operator()(Ts &&...ts)
RANGES_DECLTYPE_NOEXCEPT(composed::do_(
std::declval<First &>(),
std::declval<Second &>(),
std::is_void<FirstResultT>{},
(Ts &&) ts...))
{
return composed::do_(
first(), second(),
std::is_void<FirstResultT>{},
(Ts &&) ts...);
}
template<typename...Ts,
typename FirstResultT = result_of_t<First const &(Ts &&...)>>
auto operator()(Ts &&...ts) const
RANGES_DECLTYPE_NOEXCEPT(composed::do_(
std::declval<First const &>(),
std::declval<Second const &>(),
std::is_void<FirstResultT>{},
(Ts &&) ts...))
{
return composed::do_(
first(), second(),
std::is_void<FirstResultT>{},
(Ts &&) ts...);
}
};
struct compose_fn
{
template<typename Second, typename First>
composed<Second, First> operator()(Second second, First first) const
{
return {std::move(second), std::move(first)};
}
};
/// \ingroup group-utility
/// \sa `compose_fn`
RANGES_INLINE_VARIABLE(compose_fn, compose)
template<>
struct overloaded<>
{};
template<typename First, typename...Rest>
struct overloaded<First, Rest...>
: private compressed_pair<First, overloaded<Rest...>>
{
private:
using base_t = compressed_pair<First, overloaded<Rest...>>;
using base_t::first;
using base_t::second;
public:
overloaded() = default;
constexpr overloaded(First first, Rest... rest)
: overloaded::compressed_pair{
detail::move(first),
overloaded<Rest...>{detail::move(rest)...}}
{}
template<typename... Args>
auto operator()(Args&&...args)
RANGES_DECLTYPE_NOEXCEPT(
invoke(std::declval<First &>(),
static_cast<Args&&>(args)...))
{
return invoke(first(), static_cast<Args&&>(args)...);
}
template<typename... Args>
auto operator()(Args&&...args) const
RANGES_DECLTYPE_NOEXCEPT(
invoke(std::declval<First const &>(),
static_cast<Args&&>(args)...))
{
return invoke(first(), static_cast<Args&&>(args)...);
}
template<typename... Args>
auto operator()(Args&&...args)
RANGES_DECLTYPE_NOEXCEPT(
std::declval<overloaded<Rest...> &>()(
static_cast<Args&&>(args)...))
{
return second()(static_cast<Args&&>(args)...);
}
template<typename... Args>
auto operator()(Args&&...args) const
RANGES_DECLTYPE_NOEXCEPT(
std::declval<overloaded<Rest...> const &>()(
static_cast<Args&&>(args)...))
{
return second()(static_cast<Args&&>(args)...);
}
};
struct overload_fn
{
template<typename Fn>
constexpr Fn operator()(Fn fn) const
{
return fn;
}
template<typename ...Fns>
constexpr overloaded<Fns...> operator()(Fns... fns) const
{
return overloaded<Fns...>{detail::move(fns)...};
}
};
/// \ingroup group-utility
/// \sa `overload_fn`
RANGES_INLINE_VARIABLE(overload_fn, overload)
template<typename Fn>
struct indirected
: private box<Fn, indirected<Fn>>
{
private:
using box<Fn, indirected<Fn>>::get;
public:
indirected() = default;
indirected(Fn fn)
: indirected::box(std::move(fn))
{}
// value_type (needs no impl)
template<typename ...Its>
[[noreturn]] auto operator()(copy_tag, Its...) const ->
result_of_t<Fn &(decltype(*std::declval<Its>())...)>
{
RANGES_EXPECT(false);
}
// Reference
template<typename ...Its>
auto operator()(Its ...its)
RANGES_DECLTYPE_NOEXCEPT(invoke(std::declval<Fn &>(), *its...))
{
return invoke(get(), *its...);
}
template<typename ...Its>
auto operator()(Its ...its) const
RANGES_DECLTYPE_NOEXCEPT(invoke(std::declval<Fn const &>(), *its...))
{
return invoke(get(), *its...);
}
// Rvalue reference
template<typename ...Its>
auto operator()(move_tag, Its ...its)
noexcept(noexcept(aux::move(invoke(std::declval<Fn &>(), *its...)))) ->
aux::move_t<decltype(invoke(std::declval<Fn &>(), *its...))>
{
return aux::move(invoke(get(), *its...));
}
template<typename ...Its>
auto operator()(move_tag, Its ...its) const
noexcept(noexcept(aux::move(invoke(std::declval<Fn const &>(), *its...)))) ->
aux::move_t<decltype(invoke(std::declval<Fn const &>(), *its...))>
{
return aux::move(invoke(get(), *its...));
}
};
struct indirect_fn
{
template<typename Fn>
constexpr indirected<Fn> operator()(Fn fn) const
{
return indirected<Fn>{detail::move(fn)};
}
};
/// \ingroup group-utility
/// \sa `indirect_fn`
RANGES_INLINE_VARIABLE(indirect_fn, indirect)
template<typename Fn1, typename Fn2>
struct transformed
: private compressed_pair<Fn1, Fn2>
{
private:
using transformed::compressed_pair::first;
using transformed::compressed_pair::second;
public:
transformed() = default;
constexpr transformed(Fn1 fn1, Fn2 fn2)
: transformed::compressed_pair{detail::move(fn1), detail::move(fn2)}
{}
template<typename ...Args>
auto operator()(Args &&... args)
RANGES_DECLTYPE_NOEXCEPT(
invoke(std::declval<Fn1 &>(), invoke(std::declval<Fn2 &>(), static_cast<Args&&>(args))...))
{
return invoke(first(), invoke(second(), static_cast<Args&&>(args)...));
}
template<typename ...Args>
auto operator()(Args &&... args) const
RANGES_DECLTYPE_NOEXCEPT(
invoke(std::declval<Fn1 const &>(), invoke(std::declval<Fn2 const &>(), static_cast<Args&&>(args))...))
{
return invoke(first(), invoke(second(), static_cast<Args&&>(args)...));
}
};
struct on_fn
{
template<typename Fn1, typename Fn2>
constexpr transformed<Fn1, Fn2> operator()(Fn1 fn1, Fn2 fn2) const
{
return transformed<Fn1, Fn2>{detail::move(fn1), detail::move(fn2)};
}
};
/// \ingroup group-utility
/// \sa `on_fn`
RANGES_INLINE_VARIABLE(on_fn, on)
/// \cond
namespace detail
{
template<typename Bind>
struct pipeable_binder
: Bind
, pipeable<pipeable_binder<Bind>>
{
pipeable_binder(Bind bind)
: Bind(std::move(bind))
{}
};
template<typename Pipe0, typename Pipe1>
struct composed_pipe
{
Pipe0 pipe0_;
Pipe1 pipe1_;
template<typename Arg>
auto operator()(Arg && arg) const
RANGES_DECLTYPE_AUTO_RETURN
(
static_cast<Arg&&>(arg) | pipe0_ | pipe1_
)
};
}
/// \endcond
struct make_pipeable_fn
{
template<typename Fun>
detail::pipeable_binder<Fun> operator()(Fun fun) const
{
return {std::move(fun)};
}
};
/// \ingroup group-utility
/// \sa `make_pipeable_fn`
RANGES_INLINE_VARIABLE(make_pipeable_fn, make_pipeable)
template<typename T,
typename U = meta::if_<
std::is_lvalue_reference<T>,
std::reference_wrapper<meta::_t<std::remove_reference<T>>>,
T &&>>
U bind_forward(meta::_t<std::remove_reference<T>> &t) noexcept
{
return static_cast<U>(t);
}
template<typename T>
T && bind_forward(meta::_t<std::remove_reference<T>> &&t) noexcept
{
// This is to catch way sketchy stuff like: forward<int const &>(42)
static_assert(!std::is_lvalue_reference<T>::value, "You didn't just do that!");
return static_cast<T &&>(t);
}
struct pipeable_base
{};
template<typename T>
struct is_pipeable
: std::is_base_of<pipeable_base, T>
{};
template<typename T>
struct is_pipeable<T &>
: is_pipeable<T>
{};
struct pipeable_access
{
template<typename Pipeable>
struct impl : Pipeable
{
using Pipeable::pipe;
};
template<typename Pipeable>
struct impl<Pipeable &> : impl<Pipeable>
{};
};
template<typename Derived>
struct pipeable : pipeable_base
{
private:
friend pipeable_access;
// Default Pipe behavior just passes the argument to the pipe's function call
// operator
template<typename Arg, typename Pipe>
static auto pipe(Arg && arg, Pipe pipe)
RANGES_DECLTYPE_AUTO_RETURN
(
pipe(static_cast<Arg&&>(arg))
)
};
// Evaluate the pipe with an argument
template<typename Arg, typename Pipe,
CONCEPT_REQUIRES_(!is_pipeable<Arg>() && is_pipeable<Pipe>())>
auto operator|(Arg && arg, Pipe pipe)
RANGES_DECLTYPE_AUTO_RETURN
(
pipeable_access::impl<Pipe>::pipe(static_cast<Arg&&>(arg), pipe)
)
// Compose two pipes
template<typename Pipe0, typename Pipe1,
CONCEPT_REQUIRES_(is_pipeable<Pipe0>() && is_pipeable<Pipe1>())>
auto operator|(Pipe0 pipe0, Pipe1 pipe1)
RANGES_DECLTYPE_AUTO_RETURN
(
make_pipeable(detail::composed_pipe<Pipe0, Pipe1>{pipe0, pipe1})
)
template<typename T>
struct bind_element
: meta::if_<
std::is_same<detail::decay_t<T>, T>,
meta::id<T>,
bind_element<detail::decay_t<T>>>
{};
template<typename T>
struct bind_element<std::reference_wrapper<T>>
{
using type = T &;
};
template<typename T>
struct bind_element<reference_wrapper<T>>
{
using type = typename reference_wrapper<T>::reference;
};
template<typename T>
using bind_element_t = meta::_t<bind_element<T>>;
struct ref_fn : pipeable<ref_fn>
{
template<typename T, CONCEPT_REQUIRES_(!is_reference_wrapper_t<T>())>
reference_wrapper<T> operator()(T &t) const
{
return {t};
}
/// \overload
template<typename T>
reference_wrapper<T> operator()(reference_wrapper<T> t) const
{
return t;
}
/// \overload
template<typename T>
reference_wrapper<T> operator()(std::reference_wrapper<T> t) const
{
return {t.get()};
}
};
/// \ingroup group-utility
/// \sa `ref_fn`
RANGES_INLINE_VARIABLE(ref_fn, ref)
template<typename T>
using ref_t = decltype(ref(std::declval<T>()));
struct unwrap_reference_fn : pipeable<unwrap_reference_fn>
{
template<typename T, CONCEPT_REQUIRES_(!is_reference_wrapper<T>())>
T &&operator()(T &&t) const noexcept
{
return static_cast<T&&>(t);
}
/// \overload
template<typename T>
typename reference_wrapper<T>::reference
operator()(reference_wrapper<T> t) const noexcept
{
return t.get();
}
/// \overload
template<typename T>
T &operator()(std::reference_wrapper<T> t) const noexcept
{
return t.get();
}
};
/// \ingroup group-utility
/// \sa `unwrap_reference_fn`
RANGES_INLINE_VARIABLE(unwrap_reference_fn, unwrap_reference)
template<typename T>
using unwrap_reference_t = decltype(unwrap_reference(std::declval<T>()));
/// \cond
namespace detail
{
template<typename Bind>
struct protect
{
private:
Bind bind_;
public:
protect() = default;
protect(Bind b)
: bind_(std::move(b))
{}
template<typename...Ts>
auto operator()(Ts &&...ts)
RANGES_DECLTYPE_AUTO_RETURN
(
bind_(static_cast<Ts&&>(ts)...)
)
/// \overload
template<typename...Ts>
auto operator()(Ts &&...ts) const
RANGES_DECLTYPE_AUTO_RETURN
(
bind_(static_cast<Ts&&>(ts)...)
)
};
}
/// \endcond
struct protect_fn
{
template<typename F, CONCEPT_REQUIRES_(std::is_bind_expression<uncvref_t<F>>())>
detail::protect<uncvref_t<F>> operator()(F && f) const
{
return {static_cast<F&&>(f)};
}
/// \overload
template<typename F, CONCEPT_REQUIRES_(!std::is_bind_expression<uncvref_t<F>>())>
F operator()(F && f) const
{
return static_cast<F&&>(f);
}
};
/// Protect a callable so that it can be safely used in a bind expression without
/// accidentally becoming a "nested" bind.
/// \ingroup group-utility
/// \sa `protect_fn`
RANGES_INLINE_VARIABLE(protect_fn, protect)
// Accepts initializer_lists as either the first or second parameter, or both,
// and forwards on to an implementation.
template<typename ImplFn>
struct with_braced_init_args
: ImplFn
{
private:
constexpr ImplFn const & base() const
{
return *this;
}
public:
using ImplFn::operator();
template<typename V0, typename...Args>
constexpr
auto operator()(std::initializer_list<V0> &&rng0, Args &&...args) const ->
decltype(std::declval<ImplFn const &>()(std::move(rng0), std::declval<Args>()...))
{
return base()(std::move(rng0), static_cast<Args&&>(args)...);
}
/// \overload
template<typename Rng0, typename V1, typename...Args>
constexpr
auto operator()(Rng0 && rng0, std::initializer_list<V1> &&rng1, Args &&...args) const ->
decltype(std::declval<ImplFn const &>()(std::declval<Rng0>(), std::move(rng1), std::declval<Args>()...))
{
return base()(static_cast<Rng0&&>(rng0), std::move(rng1), static_cast<Args&&>(args)...);
}
/// \overload
template<typename V0, typename V1, typename...Args>
constexpr
auto operator()(std::initializer_list<V0> rng0, std::initializer_list<V1> &&rng1, Args &&...args) const ->
decltype(std::declval<ImplFn const &>()(std::move(rng0), std::move(rng1), std::declval<Args>()...))
{
return base()(std::move(rng0), std::move(rng1), static_cast<Args&&>(args)...);
}
};
/// @}
}
}
RANGES_RE_ENABLE_WARNINGS
#endif
|