Skip to content

Instantly share code, notes, and snippets.

@bradphelan
Last active August 28, 2019 10:24
Show Gist options
  • Save bradphelan/80fc63e7051a6bd71c15a6743400f02a to your computer and use it in GitHub Desktop.
Save bradphelan/80fc63e7051a6bd71c15a6743400f02a to your computer and use it in GitHub Desktop.
/// Handle lvalue sequence reference.
/// This means the lifetime of the input sequence should be longer than
/// the lifetime of the output sequence
template <typename Enumerable,typename Combinator>
auto
operator|(Enumerable & enumerable, Combinator c) ->
typename boost::enable_if_c
< MW_LINQ_IS_ENUMERABLE(Enumerable) && MW_LINQ_IS_LAZY_COMBINATOR(Combinator)
, EnumerableOp
< Combinator
, decltype(boost::make_iterator_range(enumerable))
>
>::type
{
return EnumerableOp
< typename std::decay<Combinator>::type
, decltype(boost::make_iterator_range(enumerable))
>
(boost::make_iterator_range(enumerable), c);
}
/// Handle rvalue sequence reference. The sequence will
/// be moved into the operator. This is useful if you
/// wish to return a sequence from a function. If your
/// input sequence is an rvalue then it will get moved.
template <typename Enumerable,typename Combinator>
auto
operator|(Enumerable && enumerable, Combinator c) ->
typename boost::enable_if_c
< MW_LINQ_IS_ENUMERABLE(Enumerable) && MW_LINQ_IS_LAZY_COMBINATOR(Combinator) && !std::is_lvalue_reference<Enumerable>::value
, EnumerableOp
< Combinator
, Enumerable
>
>::type
{
return EnumerableOp
< Combinator
, Enumerable
>
(std::move(enumerable), c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment