Created
January 19, 2016 08:55
-
-
Save sehe/e6d23d0ad94d89601f37 to your computer and use it in GitHub Desktop.
mutable_wrapper
This file contains hidden or 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
#include <vector> | |
#include <iterator> | |
struct X { | |
X() = default; | |
X(X&&) = default; | |
X(X const&) = delete; | |
}; | |
template<typename Val> | |
struct mutable_wrapper { | |
mutable Val value; | |
constexpr operator Val&() const& | |
{ return value; } | |
constexpr operator Val&&() const&& | |
{ return std::move(value); } | |
}; | |
template<typename Val> | |
constexpr mutable_wrapper<Val> mut(Val&& val) | |
{ return { std::forward<Val>(val) }; } | |
int main() { | |
auto xs = { mut(X {}), mut(X {}), mut(X {}) }; | |
auto xv = std::vector<X> { std::make_move_iterator(begin(xs)), std::make_move_iterator(end(xs)) }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment