Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParameterDescriptors: make more composable by adding insert function #107

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion include/clients/common/ParameterSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
constexpr ParameterDescriptorSet(const Ts&&... ts)
: mDescriptors{std::make_tuple(ts...)}
{}
constexpr ParameterDescriptorSet(const std::tuple<Ts...>&& t)
constexpr ParameterDescriptorSet(const std::tuple<Ts...>& t)
: mDescriptors{t}
{}

Expand Down Expand Up @@ -623,6 +623,19 @@ constexpr ParamDescTypeFor<Args...> defineParameters(Args&&... args)
return {std::forward<Args>(args)...};
}

template<typename...Ts>
constexpr ParamDescTypeFor<Ts...> defineParametersFromTuple(const std::tuple<Ts...>& t)
{
return {t};
}

template <size_t N,typename P, typename... Args>
constexpr auto insertParameterAfter(ParamDescTypeFor<Args...> d,const P&& param)
{
return defineParametersFromTuple(impl::tupleInsertAfter<N>(d.descriptors(),param));
}


auto constexpr NoParameters = defineParameters();

} // namespace client
Expand Down
44 changes: 44 additions & 0 deletions include/clients/common/TupleUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,50 @@ constexpr size_t zeroAll()
template <typename... Ts>
using zeroSequenceFor = std::index_sequence<zeroAll<Ts>()...>;


template<typename T>
constexpr std::tuple<T> Include(T& t, std::true_type)
{
return std::make_tuple(t);
}

template<typename T>
constexpr std::tuple<> Include(T&, std::false_type)
{
return std::make_tuple();
}

template<size_t N,typename...Ts,size_t...Is>
constexpr auto tupleHead_impl(const std::tuple<Ts...>& t,std::index_sequence<Is...>)
{
return std::tuple_cat(Include(std::get<Is>(t),std::integral_constant<bool, (Is < N)>{})...);
}

template<size_t N,typename...Ts>
constexpr auto tupleHead(const std::tuple<Ts...>& t)
{
return tupleHead_impl<N>(t,std::make_index_sequence<sizeof...(Ts)>{});
}

template<size_t N,typename...Ts,size_t...Is>
constexpr auto tupleTail_impl(const std::tuple<Ts...>& t,std::index_sequence<Is...>)
{
return std::tuple_cat(Include(std::get<Is>(t),std::integral_constant<bool,(Is >= N)>{})...);
}

template<size_t N,typename...Ts>
constexpr auto tupleTail(const std::tuple<Ts...>& t)
{
return tupleTail_impl<N>(t,std::make_index_sequence<sizeof...(Ts)>{});
}

template<size_t N,typename T, typename...Ts>
constexpr auto tupleInsertAfter(const std::tuple<Ts...>& t, T&& x)
{
return std::tuple_cat(tupleHead<N>(t), std::make_tuple(std::forward<T>(x)),
tupleTail<N>(t));
}

} // namespace impl
} // namespace client
} // namespace fluid