On 5/17/2011 1:06 AM, Syron wrote:
> Before I fell asleep last night, I had the following idea for in-class member initialization with no runtime overhead. What do you think?
>
> #define INCLASS_INIT(ctype, name, ...) \
> class _ ## name ## _INIT { \
> private: ctype m_data; \
> public: \
> inline _ ## name ## _INIT() : \
> m_data(__VA_ARGS__) {} \
> inline _ ## name ## _INIT(const ctype& v) : \
> m_data(v) {} \
> inline operator ctype&() \
> { return m_data; } \
> inline operator const ctype&() const \
> { return m_data; } \
> inline ctype* operator&() \
> { return&m_data; } \
> inline const ctype* operator&() const \
> { return&m_data; } \
> inline ctype& operator=(const ctype& v) \
> { return m_data=v; } \
> } name
>
> // Usage:
> class Foo {
> public:
> INCLASS_INIT(int, m_v1, 1);
> INCLASS_INIT(int, m_v2, 2);
> Foo() : m_v2(3)
This is confusing. What's the value of m_v2? I see it initialized to
'3' here, but is that what I'd see when I try using it elsewhere?
> {}
> };
Curious (like a two-headed calf), but what's the point? Also, is it
intentionally limited to simple types? For instance, you can't declare
a reference that way, can you?
V
--
I do not respond to top-posted replies, please don't ask
|