Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active December 16, 2015 09:28
Show Gist options
  • Save klmr/5412724 to your computer and use it in GitHub Desktop.
Save klmr/5412724 to your computer and use it in GitHub Desktop.
template <typename Source>
struct auto_cast_helper {
Source const& value;
explicit auto_cast_helper(Source const& value) : value(value) { }
template <typename Target>
operator Target() const {
return static_cast<Target>(value);
}
};
template <typename Source>
auto_cast_helper<Source> auto_cast(Source const& value) {
return auto_cast_helper<Source>(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment