Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lame wrapper for `hana::partial` to use `std::ref`s
//
// Copyright Jason Rice 2016
// 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 NBDL_DETAILS_PARTIAL_REF_HPP
#define NBDL_DETAILS_PARTIAL_REF_HPP
#include<boost/hana.hpp>
#include<functional>
namespace nbdl {
namespace details {
namespace hana = boost::hana;
struct RefWrap
{
template<typename T>
constexpr auto operator()(T const& t) const
{
return std::cref(t);
}
};
constexpr RefWrap ref_wrap{};
struct RefUnwrap
{
template<typename T>
constexpr auto operator()(std::reference_wrapper<T> const& t) const
{
return t.get();
}
};
constexpr RefUnwrap ref_unwrap{};
struct PartialRef
{
template<typename F, typename... Args>
constexpr auto operator()(F const& f, Args const& ...args) const
{
return hana::on(hana::partial(f ^hana::on^ ref_unwrap, std::cref(args)...), ref_wrap);
}
};
constexpr PartialRef partial_ref{};
struct ReversePartialRef
{
template<typename F, typename... Args>
constexpr auto operator()(F const& f, Args const& ...args) const
{
return hana::on(hana::reverse_partial(f ^hana::on^ ref_unwrap, std::cref(args)...), ref_wrap);
}
};
constexpr ReversePartialRef reverse_partial_ref{};
}//details
}//nbdl
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.