Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit underlying cast #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions named_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class NamedTypeImpl : public Skills<NamedTypeImpl<T, Parameter, Converter, Skill
using UnderlyingType = T;

// constructor
NamedTypeImpl() = default;
explicit NamedTypeImpl(T const& value) : value_(value) {}
template<typename T_ = T>
explicit NamedTypeImpl(T&& value, typename std::enable_if<!std::is_reference<T_>::value, std::nullptr_t>::type = nullptr) : value_(std::move(value)) {}
Expand All @@ -31,6 +32,9 @@ class NamedTypeImpl : public Skills<NamedTypeImpl<T, Parameter, Converter, Skill
T& get() { return value_; }
T const& get() const {return value_; }

// explicit cast to underlying
explicit operator T() const { return value_; }

// conversions
template <typename Converter2>
operator NamedTypeImpl<T, Parameter, Converter2, Skills...>() const
Expand All @@ -52,7 +56,7 @@ class NamedTypeImpl : public Skills<NamedTypeImpl<T, Parameter, Converter, Skill
};

private:
T value_;
T value_{};
};

template <typename T, typename Parameter, template<typename> class... Skills>
Expand All @@ -69,7 +73,7 @@ StrongType<T> make_named(T const& value)
{
return StrongType<T>(value);
}

} // namespace fluent

#endif