Skip to content

Commit

Permalink
Merge pull request #679 from CaseyCarter/relax_view
Browse files Browse the repository at this point in the history
Allow move-only single-pass Views
  • Loading branch information
ericniebler committed Jun 30, 2017
2 parents c3ddc64 + 53bb133 commit cb42d1c
Show file tree
Hide file tree
Showing 45 changed files with 1,027 additions and 391 deletions.
2 changes: 1 addition & 1 deletion include/range/v3/istream_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ranges
private:
friend range_access;
std::istream *sin_;
semiregular_t<Val> obj_;
movesemiregular_t<Val> obj_;
struct cursor
{
private:
Expand Down
5 changes: 2 additions & 3 deletions include/range/v3/range_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ namespace ranges
///

struct View
: refines<Range>
: refines<Range, Movable, DefaultConstructible>
{
template<typename T>
auto requires_() -> decltype(
concepts::valid_expr(
concepts::model_of<SemiRegular, T>(),
concepts::is_true(detail::view_predicate_<T>())
));
};
Expand All @@ -223,7 +222,7 @@ namespace ranges
{};

struct ForwardView
: refines<InputView, ForwardRange>
: refines<InputView, ForwardRange, Copyable>
{};

struct BidirectionalView
Expand Down
10 changes: 9 additions & 1 deletion include/range/v3/utility/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

#include <memory>
#include <type_traits>
#include <range/v3/range_fwd.hpp>
#include <meta/meta.hpp>
#include <range/v3/detail/config.hpp>
#include <range/v3/utility/iterator_concepts.hpp>
#include <range/v3/utility/iterator_traits.hpp>
#include <range/v3/utility/polymorphic_cast.hpp>

namespace ranges
{
Expand All @@ -44,6 +45,13 @@ namespace ranges
std::return_temporary_buffer(p);
}
};

template<typename T, typename... Args,
CONCEPT_REQUIRES_(!std::is_array<T>::value)>
std::unique_ptr<T> make_unique(Args &&... args)
{
return std::unique_ptr<T>{new T(static_cast<Args &&>(args)...)};
}
}
/// \endcond

Expand Down
26 changes: 23 additions & 3 deletions include/range/v3/utility/polymorphic_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,37 @@

#ifndef RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP
#define RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP

#include <memory>
#include <type_traits>
#include <meta/meta.hpp>
#include <range/v3/detail/config.hpp>

namespace ranges
{
inline namespace v3
{
template<typename Target, typename Source>
inline Target polymorphic_downcast(Source* x)
auto polymorphic_downcast(Source *x) noexcept ->
meta::if_<std::is_pointer<Target>,
decltype((static_cast<Target>(x), dynamic_cast<Target>(x)))>
{
auto result = static_cast<Target>(x);
RANGES_ASSERT(dynamic_cast<Target>(x) == result);
return result;
}
template<typename Target, typename Source>
auto polymorphic_downcast(Source &&x) noexcept ->
meta::if_<std::is_reference<Target>,
decltype((static_cast<Target>(std::declval<Source>()),
dynamic_cast<Target>(std::declval<Source>())))>
{
RANGES_ASSERT(dynamic_cast<Target>(x) == x);
return static_cast<Target>(x);
auto &&result = static_cast<Target>(static_cast<Source &&>(x));
#ifndef NDEBUG
auto &&dresult = dynamic_cast<Target>(static_cast<Source &&>(x));
RANGES_ASSERT(std::addressof(dresult) == std::addressof(result));
#endif
return static_cast<Target>(result);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions include/range/v3/utility/semiregular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ namespace ranges
using semiregular_t =
meta::if_<SemiRegular<T>, T, semiregular<T>>;

template<typename T>
using movesemiregular_t =
meta::if_c<
Movable<T>() && DefaultConstructible<T>(),
T,
semiregular<T>>;

template<typename T, bool IsConst = false>
using semiregular_ref_or_val_t =
meta::if_<
Expand Down

0 comments on commit cb42d1c

Please sign in to comment.