What's wrong with defining them outside of the scope of the class?
On 03/26/2017 05:35 PM, Nicol Bolas wrote:
You can do that already, within an inline member function.On Sunday, March 26, 2017 at 10:30:29 AM UTC-4, Avi Kivity wrote:Consider this type-safe bool class:
template <typename Tag>
class bool_class {
bool _value;
public:
explicit constexpr bool_class(bool v) noexcept : _value(v) {}
// more emulation of bool
static constexpr bool_class yes = bool_class{true};
static constexpr bool_class no = bool_class{true};
};
Compilation fails, I believe rightly, on clang, because by the time yes
and no are parsed, bool_class is an incomplete type, and therefore not a
literal type. It could be worked around by making yes and no functions.
Should we make this legal? It seems reasonable for types to offer
constants scoped under their own name, and if they are literal types,
that these constants can be constexpr.
How does it seem reasonable to define variables of a type that has not yet been defined?
Should we make this legal? It seems reasonable for types to offer
constants scoped under their own name, and if they are literal types,
that these constants can be constexpr.
Am Mittwoch, 19. April 2017 18:45:15 UTC+2 schrieb HarD Gamer:This basically represents a work-around but I hardly considerinline variable definitions outside of the class in which they are declared as intuitive.To my knowledge, there are only historical reasons thatstatic variables of a class should not be defined insidethat class but instead declared inside and definedoutside of the class and in only one source file.In order to fish or cut bait w.r.t. a proposal, I'd be interested in three things:1. Are there any reasons against allowing the definition of constexpr static class members of the containing class type within this class itself?
2. Are there any reasons against allowing the definition of (non-constexpr) static class members of the containing class type within this class as well?3. From question 1 and 2 stems the question: Can we just allow static class members to be defined inside the class itself, as if they'd been defined outside of the class as inline variable?Am I mistaken at some point?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/285f811f-044a-4121-a107-c463bd0693e1%40isocpp.org.
On 29 April 2017 at 14:51, Jakob Riedle <jakob....@gmail.com> wrote:
Am Mittwoch, 19. April 2017 18:45:15 UTC+2 schrieb HarD Gamer:
This basically represents a work-around but I hardly considerinline variable definitions outside of the class in which they are declared as intuitive.
To my knowledge, there are only historical reasons thatstatic variables of a class should not be defined insidethat class but instead declared inside and definedoutside of the class and in only one source file.
In order to fish or cut bait w.r.t. a proposal, I'd be interested in three things:1. Are there any reasons against allowing the definition of constexpr static class members of the containing class type within this class itself?
Yes. The class is not yet completely defined at that point.
----2. Are there any reasons against allowing the definition of (non-constexpr) static class members of the containing class type within this class as well?3. From question 1 and 2 stems the question: Can we just allow static class members to be defined inside the class itself, as if they'd been defined outside of the class as inline variable?
Am I mistaken at some point?
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/285f811f-044a-4121-a107-c463bd0693e1%40isocpp.org.
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqmTeRnDL9mTSyo49f%2BzjgwiY4C%2BhUKp%3DHD715K1i7S3fw%40mail.gmail.com.