Skip to content

Instantly share code, notes, and snippets.

@sehe
Created January 19, 2016 08:55
Show Gist options
  • Save sehe/e6d23d0ad94d89601f37 to your computer and use it in GitHub Desktop.
Save sehe/e6d23d0ad94d89601f37 to your computer and use it in GitHub Desktop.
mutable_wrapper
#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