-
Notifications
You must be signed in to change notification settings - Fork 34
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
strong::underlying_type_t #49
Comments
The answer is that it honestly never occurred to me that this would be a use case. Why do you want to have a const underlying type? I think the comparison with |
I only used span as an example, maybe shared_ptr or similar would be better. I ran into this when I wanted to do strong::type<std::string const,...>. This was being used to represent some strings that should never change, in my case ISO defined country names. In this case I may switch to using some fixed_string type like https://github.com/unterumarmung/fixed_string. Note copying these things is fine but in general it's a coding error to try to change the values.
|
The problem with Maybe you should write your own type, maybe implemented in terms of class country_name
{
public:
explicit country_name(std::string name) : name_(std::move(name)) {}
country_name& operator=(const country_name&) = delete;
explicit operator std::string_view() const { return name_; }
// probably others too...
private:
std::string name_;
}; A truly Machiavellian user can, of course, subvert the type system completely and do whatever they please, but it takes a little effort and is very visible. Or, you can use struct country_name : strong::type<std::string,
country_name,
strong::ostreamable,
strong::convertible_to<std::string_view>,
strong::equality, strong::equality_with<std::string_view>>
{
using type::type;
country_name& operator=(const country_name&) = delete;
}; Now, this can be modified using This makes me think I should probably add a modifier that disallows assignment. |
Would this work? https://godbolt.org/z/n9853n3ex I'd have to figure out a way to make |
Try branch immutable and tell me if it's OK for your use case. You use it with a non-const underlying type, and a |
I have a question about the following
The static_asset fails as the type T is an
int
not aint const
.I am wondering if this is deliberate? I certainly found it surprising.
This happens because the
underlying_type_t
is implemented by returning a instance of the underlying type andI am wondering why you don't use member types in
strong::type
I.E.like
std::span
does.The text was updated successfully, but these errors were encountered: