Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ricejasonf
Created January 14, 2016 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricejasonf/78f62e74d9dec0d72bbf to your computer and use it in GitHub Desktop.
Save ricejasonf/78f62e74d9dec0d72bbf to your computer and use it in GitHub Desktop.
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