Skip to content

Commit

Permalink
extract container related type traits into ureact/detail/container_ty…
Browse files Browse the repository at this point in the history
…pe_traits.hpp
  • Loading branch information
YarikTH committed Jul 16, 2023
1 parent 2cc6290 commit 4aca266
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
28 changes: 1 addition & 27 deletions include/ureact/adaptor/collect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,13 @@

#include <ureact/adaptor/fold.hpp>
#include <ureact/detail/adaptor.hpp>
#include <ureact/detail/container_type_traits.hpp>

UREACT_BEGIN_NAMESPACE

namespace detail
{

template <typename Cont, typename Value, typename = void>
struct has_push_back_method : std::false_type
{};

template <typename Cont, class Value>
struct has_push_back_method<Cont,
Value,
std::void_t<decltype( std::declval<Cont>().push_back( std::declval<Value>() ) )>>
: std::true_type
{};

template <typename Cont, class Value>
inline constexpr bool has_push_back_method_v = has_push_back_method<Cont, Value>::value;

template <typename Cont, typename Value, typename = void>
struct has_insert_method : std::false_type
{};

template <typename Cont, class Value>
struct has_insert_method<Cont,
Value,
std::void_t<decltype( std::declval<Cont>().insert( std::declval<Value>() ) )>> : std::true_type
{};

template <typename Cont, class Value>
inline constexpr bool has_insert_method_v = has_insert_method<Cont, Value>::value;

template <template <typename...> class ContT>
struct CollectClosure : AdaptorClosure
{
Expand Down
10 changes: 1 addition & 9 deletions include/ureact/adaptor/join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@
#define UREACT_ADAPTOR_JOIN_HPP

#include <ureact/adaptor/process.hpp>
#include <ureact/detail/container_type_traits.hpp>

UREACT_BEGIN_NAMESPACE

namespace detail
{

template <class ContainerT>
struct container_value
{
using type = std::decay_t<decltype( *std::begin( std::declval<ContainerT>() ) )>;
};

template <class ContainerT>
using container_value_t = typename container_value<ContainerT>::type;

struct JoinClosure : AdaptorClosure
{
/*!
Expand Down
63 changes: 63 additions & 0 deletions include/ureact/detail/container_type_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Copyright (C) 2014-2017 Sebastian Jeckel.
// Copyright (C) 2020-2023 Krylov Yaroslav.
//
// Distributed under 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)
//

#ifndef UREACT_DETAIL_CONTAINER_TYPE_TRAITS_HPP
#define UREACT_DETAIL_CONTAINER_TYPE_TRAITS_HPP

#include <type_traits>
#include <vector> // for std::begin(). It is declared in core headers anyway

#include <ureact/detail/defines.hpp>

UREACT_BEGIN_NAMESPACE

namespace detail
{

template <typename Cont, typename Value, typename = void>
struct has_push_back_method : std::false_type
{};

template <typename Cont, class Value>
struct has_push_back_method<Cont,
Value,
std::void_t<decltype( std::declval<Cont>().push_back( std::declval<Value>() ) )>>
: std::true_type
{};

template <typename Cont, class Value>
inline constexpr bool has_push_back_method_v = has_push_back_method<Cont, Value>::value;

template <typename Cont, typename Value, typename = void>
struct has_insert_method : std::false_type
{};

template <typename Cont, class Value>
struct has_insert_method<Cont,
Value,
std::void_t<decltype( std::declval<Cont>().insert( std::declval<Value>() ) )>> : std::true_type
{};

template <typename Cont, class Value>
inline constexpr bool has_insert_method_v = has_insert_method<Cont, Value>::value;

template <class ContainerT>
struct container_value
{
using type = std::decay_t<decltype( *std::begin( std::declval<ContainerT>() ) )>;
};

template <class ContainerT>
using container_value_t = typename container_value<ContainerT>::type;

} // namespace detail

UREACT_END_NAMESPACE

#endif //UREACT_DETAIL_CONTAINER_TYPE_TRAITS_HPP

0 comments on commit 4aca266

Please sign in to comment.