Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Optional in STL?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
DeMarcus  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:21
Newsgroups: comp.lang.c++.moderated
From: DeMarcus <use_my_alias_h...@hotmail.com>
Date: Sat, 7 Nov 2009 09:21:38 CST
Local: Sat 7 Nov 2009 15:21
Subject: Optional in STL?
Hi!

Is there, or will be, anything equivalent to boost::optional in STL?

Thanks,
Daniel

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yechezkel Mett  
View profile   Translate to Translated (View Original)
 More options 9 Nov, 20:27
Newsgroups: comp.lang.c++.moderated
From: Yechezkel Mett <ymett.on.use...@gmail.com>
Date: Mon, 9 Nov 2009 14:27:04 CST
Local: Mon 9 Nov 2009 20:27
Subject: Re: Optional in STL?
On Nov 7, 5:21 pm, DeMarcus <use_my_alias_h...@hotmail.com> wrote:

> Hi!

> Is there, or will be, anything equivalent to boost::optional in STL?

Currently there isn't. According to
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2870.html
it is planned for a future Library TR, but that means after C++0x is
finished.

Yechezkel Mett

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seungbeom Kim  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 08:23
Newsgroups: comp.lang.c++.moderated
From: Seungbeom Kim <musip...@bawi.org>
Date: Tue, 10 Nov 2009 02:23:02 CST
Local: Tues 10 Nov 2009 08:23
Subject: Re: Optional in STL?

Yechezkel Mett wrote:
> On Nov 7, 5:21 pm, DeMarcus <use_my_alias_h...@hotmail.com> wrote:
>> Hi!

>> Is there, or will be, anything equivalent to boost::optional in STL?

> Currently there isn't. According to
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2870.html
> it is planned for a future Library TR, but that means after C++0x is
> finished.

That's too bad. I expect 'optional' to gain much wider use once it's
standardized; it enables a very useful and natural idiom of

     optional<Ret> function(Args...);
     if (optional<Ret> r = function(args...)) {
         // use *r
     }
     else {
         // error
     }

instead of

     bool function(Args..., Ret&);
     Ret r;                      // a default ctor is necessary
     if (function(args..., r)) {
         // use r
     }
     else {
         // error
     }

--
Seungbeom Kim

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Schwab  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 14:20
Newsgroups: comp.lang.c++.moderated
From: Jeff Schwab <j...@schwabcenter.com>
Date: Tue, 10 Nov 2009 08:20:33 CST
Local: Tues 10 Nov 2009 14:20
Subject: Re: Optional in STL?

Seungbeom Kim wrote:
>>> Is there, or will be, anything equivalent to boost::optional in STL?
> I expect 'optional' to gain much wider use once it's
> standardized; it enables a very useful and natural idiom of

>     optional<Ret> function(Args...);
>     if (optional<Ret> r = function(args...)) {
>         // use *r
>     }
>     else {
>         // error
>     }

I can see why you would want this in the standard, but the syntax is
definitely not what I would call "natural."  optional<Ret> certainly
looks like a smart-pointer, but IIUC, it does not have reference
semantics; e.g., it performs deep copy.  When I see something being used
as a pointer, I don't want to have to shift my mind sideways to remember
  that it behaves completely differently.  This looks like auto_ptr all
over again.  I'm not saying it isn't useful, but could we please use
different syntax?  Instead of overloading the dereference operator, for
example, a value() member function would be less confusing.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ulrich Eckhardt  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 21:22
Newsgroups: comp.lang.c++.moderated
From: Ulrich Eckhardt <eckha...@satorlaser.com>
Date: Tue, 10 Nov 2009 15:22:08 CST
Local: Tues 10 Nov 2009 21:22
Subject: Re: Optional in STL?

Jeff Schwab wrote:
> Seungbeom Kim wrote:
>> I expect 'optional' to gain much wider use once it's
>> standardized; it enables a very useful and natural idiom of

>>     optional<Ret> function(Args...);
>>     if (optional<Ret> r = function(args...)) {
>>         // use *r
>>     }
>>     else {
>>         // error
>>     }

Just for the record, this is IMHO a bad example. If something is an error,
not just one possible state, the function already should have thrown an
exception. Returning an optional is useless then.

> I can see why you would want this in the standard, but the syntax is
> definitely not what I would call "natural."  optional<Ret> certainly
> looks like a smart-pointer, but IIUC, it does not have reference
> semantics; e.g., it performs deep copy.

...unless the value is moved instead of copied.

> When I see something being used as a pointer, I don't want to have to
> shift my mind sideways to remember that it behaves completely
> differently.  This looks like auto_ptr all over again.  I'm not saying
> it isn't useful, but could we please use different syntax?  Instead of
> overloading the dereference operator, for example, a value() member
> function would be less confusing.

Boost.Optional is a container for at most one element. It has an operator*
to retrieve or operator-> to access the content. It can be used in a
boolean expression, which yields true if it has an element. I shifted my
mind in a way that operators * and -> only mean some kind of access through
a handle object, regardless of where the referenced object lives. This more
abstract view on those fits both pointers, smart pointers and various
handle types.

With this mindset, I personally can live well with the syntax. For all
others, there is the get() function that does what you want.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin B.  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 21:33
Newsgroups: comp.lang.c++.moderated
From: "Martin B." <0xCDCDC...@gmx.at>
Date: Tue, 10 Nov 2009 15:33:38 CST
Local: Tues 10 Nov 2009 21:33
Subject: Re: Optional in STL?

As far as I understood optional is intended to combine the pointer
feature of having a null value with automatic storage (no heap twiddling).
So I find the pointer syntax OK.

> over again.  I'm not saying it isn't useful, but could we please use
> different syntax?  Instead of overloading the dereference operator, for
> example, a value() member function would be less confusing.

There is the member function get() for those who prefer it.

br,
Martin

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seungbeom Kim  
View profile   Translate to Translated (View Original)
 More options 11 Nov, 05:15
Newsgroups: comp.lang.c++.moderated
From: Seungbeom Kim <musip...@bawi.org>
Date: Tue, 10 Nov 2009 23:15:36 CST
Local: Wed 11 Nov 2009 05:15
Subject: Re: Optional in STL?

There are "errors" (with quotes) that are not that "exceptional",
as when you would just return a null pointer. And we may not have
such a sentinel value for non-pointer types.

--
Seungbeom Kim

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
DeMarcus  
View profile   Translate to Translated (View Original)
 More options 12 Nov, 01:02
Newsgroups: comp.lang.c++.moderated
From: DeMarcus <use_my_alias_h...@hotmail.com>
Date: Wed, 11 Nov 2009 19:02:29 CST
Local: Thurs 12 Nov 2009 01:02
Subject: Re: Optional in STL?

As for me, that work a lot with databases, I use the null value as
"missing" value. It's not an error. I want to use Optional so I don't
have to allocate an int on the heap just to be able to get a pointer
that can have a null (missing) value.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google