Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions phlex/metaprogramming/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ cet_make_library(

install(FILES delegate.hpp type_deduction.hpp DESTINATION include/phlex/metaprogramming)

install(
FILES
detail/basic_concepts.hpp
detail/ctor_reflect_types.hpp
detail/number_output_objects.hpp
detail/number_parameters.hpp
detail/parameter_types.hpp
detail/return_type.hpp
DESTINATION include/phlex/metaprogramming/detail
)
install(FILES detail/ctor_reflect_types.hpp DESTINATION include/phlex/metaprogramming/detail)

add_library(phlex::metaprogramming ALIAS phlex_metaprogramming_int)
9 changes: 0 additions & 9 deletions phlex/metaprogramming/detail/basic_concepts.hpp

This file was deleted.

63 changes: 0 additions & 63 deletions phlex/metaprogramming/detail/number_output_objects.hpp

This file was deleted.

40 changes: 0 additions & 40 deletions phlex/metaprogramming/detail/number_parameters.hpp

This file was deleted.

32 changes: 0 additions & 32 deletions phlex/metaprogramming/detail/parameter_types.hpp

This file was deleted.

31 changes: 0 additions & 31 deletions phlex/metaprogramming/detail/return_type.hpp

This file was deleted.

67 changes: 28 additions & 39 deletions phlex/metaprogramming/type_deduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
#define PHLEX_METAPROGRAMMING_TYPE_DEDUCTION_HPP

#include "phlex/metaprogramming/detail/ctor_reflect_types.hpp"
#include "phlex/metaprogramming/detail/number_output_objects.hpp"
#include "phlex/metaprogramming/detail/number_parameters.hpp"
#include "phlex/metaprogramming/detail/parameter_types.hpp"
#include "phlex/metaprogramming/detail/return_type.hpp"

#include "boost/callable_traits.hpp"
#include "boost/mp11/algorithm.hpp"
#include "boost/mp11/list.hpp"

#include <atomic>
#include <iterator>
#include <tuple>
#include <type_traits>

namespace phlex::experimental {
namespace ct = boost::callable_traits;
namespace mp11 = boost::mp11;
template <typename T>
using return_type = decltype(detail::return_type_impl(std::declval<T>()));
using return_type = ct::return_type_t<T>;

// A simple mp_if doesn't work because both branches always need to be valid.
// With eval_if and eval_if_not the false branch doesn't need to be valid, but
// does need to be expressed in this F, Args... format.
template <typename T>
using function_parameter_types = decltype(detail::parameter_types_impl(std::declval<T>()));
using function_parameter_types =
mp11::mp_eval_if_not<std::is_member_pointer<T>, ct::args_t<T>, mp11::mp_rest, ct::args_t<T>>;
Comment thread
beojan marked this conversation as resolved.
Outdated

template <std::size_t I, typename T>
using function_parameter_type = std::tuple_element_t<I, function_parameter_types<T>>;
Expand All @@ -26,37 +32,30 @@ namespace phlex::experimental {
using constructor_parameter_types = typename refl::as_tuple<T>;

template <typename T>
constexpr std::size_t number_parameters = detail::number_parameters_impl<T>;
constexpr std::size_t number_parameters = mp11::mp_size<function_parameter_types<T>>::value;

// Wrapping in a tuple then "flattening" (which just removes one nested inner layer of tuple)
// ensures a single T by itself becomes std::tuple<T> without changing anything that's already
// a tuple.
template <typename T>
constexpr std::size_t number_output_objects = detail::number_output_objects_impl<T>;

using detail::number_types;

namespace detail {
template <typename Head, typename... Tail>
std::tuple<Tail...> skip_first_type_impl(std::tuple<Head, Tail...> const&);
constexpr std::size_t number_types = mp11::mp_size<mp11::mp_flatten<std::tuple<T>>>::value;
Comment thread
beojan marked this conversation as resolved.

template <typename Head, typename... Tail>
std::tuple<Tail...> skip_first_type_impl(std::pair<Head, Tail...> const&);
}
// Like the above on return_type<T> except we drop voids after wrapping in a tuple.
// This means a plain void return type will return 0, not 1
template <typename T>
constexpr std::size_t number_output_objects = mp11::mp_size<
mp11::mp_flatten<mp11::mp_remove_if<std::tuple<return_type<T>>, std::is_void>>>::value;
Comment thread
beojan marked this conversation as resolved.
Outdated

template <typename Tuple>
using skip_first_type = decltype(detail::skip_first_type_impl(std::declval<Tuple>()));
using skip_first_type = mp11::mp_rest<mp11::mp_apply<std::tuple, Tuple>>;
Comment thread
knoepfel marked this conversation as resolved.

template <typename T, typename... Args>
struct check_parameters {
using input_parameters = function_parameter_types<T>;
static_assert(std::tuple_size<input_parameters>{} >= sizeof...(Args));

template <std::size_t... Is>
static constexpr bool check_params_for(std::index_sequence<Is...>)
{
return std::conjunction_v<std::is_same<std::tuple_element_t<Is, input_parameters>, Args>...>;
}

static constexpr bool value =
mp11::mp_starts_with<input_parameters, std::tuple<Args...>>::value;
constexpr operator bool() noexcept { return value; }
static constexpr bool value = check_params_for(std::index_sequence_for<Args...>{});
};

// ===================================================================
Expand All @@ -66,20 +65,10 @@ namespace phlex::experimental {
template <typename T>
struct is_non_const_lvalue_reference<T const&> : std::false_type {};

// mp_similar<std::atomic<int>, T> just checks if T is an atomic (of any type)
template <typename T>
class remove_atomic {
public:
using type = T;
};

template <typename T>
class remove_atomic<std::atomic<T>> {
public:
using type = T;
};

template <typename T>
using remove_atomic_t = remove_atomic<T>::type;
using remove_atomic_t =
mp11::mp_eval_if_not<mp11::mp_similar<std::atomic<int>, T>, T, mp11::mp_front, T>;

template <typename T>
concept container = requires {
Expand Down
Loading