Created
January 14, 2016 04:40
-
-
Save ricejasonf/78f62e74d9dec0d72bbf to your computer and use it in GitHub Desktop.
Lame wrapper for `hana::partial` to use `std::ref`s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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