Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: braced-init-list form of a condition

27 views
Skip to first unread message
Message has been deleted

Victor Bazarov

unread,
Jun 30, 2015, 4:39:06 PM6/30/15
to
On 6/30/2015 4:16 PM, Stefan Ram wrote:
> There is a specification for C++ that contains this noun phrase:
>
> braced-init-list form of a condition
>
> in 8.5p16. What does this refer to?
>
> Could it refer to
>
> if( bool b{ true }) ...
>
> ?

I think the 'condition' requires an equal sign if it's a declaration of
a variable. IOW, it could be

if (bool b = {true})

Of course it makes more sense with a class that has a conversion to bool
defined for it and has a c-tor to initialize it from a list, so you can
write

class MySpecialClass
{
public:
MySpecialClass(std::initializer_list<int> list);
operator bool() const;
};

int main()
{
if (MySpecialClass obj = { 42, 666 })
return 0;
}


V
--
I do not respond to top-posted replies, please don't ask
Message has been deleted
Message has been deleted

Victor Bazarov

unread,
Jun 30, 2015, 8:54:07 PM6/30/15
to
On 6/30/2015 4:52 PM, Stefan Ram wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> Victor Bazarov <v.ba...@comcast.invalid> writes:
>>> I think the 'condition' requires an equal sign if it's a declaration of
>>> a variable.
>> The equals sign is not required. I quote 6.4p1:
>> condition:
>
> Of course, the English meaning of »condition« is something else.
> My course participants heavily protested when I
>
> #include <cstdio>
>
> int main() { if( ::std::puts( "hello, world" )){} }
>
> , and I just wanted to show that you can program without the
> semicolon »;«!

You can't guarantee that <cstdio> header does not contain a semicolon.

Ian Collins

unread,
Jun 30, 2015, 9:55:19 PM6/30/15
to
Stefan Ram wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> Victor Bazarov <v.ba...@comcast.invalid> writes:
>>> I think the 'condition' requires an equal sign if it's a declaration of
>>> a variable.
>> The equals sign is not required. I quote 6.4p1:
>> condition:
>
> Of course, the English meaning of »condition« is something else.
> My course participants heavily protested when I
>
> #include <cstdio>
>
> int main() { if( ::std::puts( "hello, world" )){} }
>
> , and I just wanted to show that you can program without the
> semicolon »;«!

You can also program without the superfluous colons!

--
Ian Collins
0 new messages