Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #14603

Re: A question on "uncopyable" that disable copy constructor

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: A question on "uncopyable" that disable copy constructor
Date Wed, 29 Feb 2012 11:15:50 +1300
Lines 49
Message-ID <9r520mFcg8U6@mid.individual.net> (permalink)
References <22985212.2610.1329972334326.JavaMail.geo-discussion-forums@ynnk21> <slrnjkieqh.1ls.grahn+nntp@frailea.sa.invalid> <jig452$rua$1@dont-email.me> <slrnjkn9pb.1ls.grahn+nntp@frailea.sa.invalid> <jiga7c$4rs$1@dont-email.me> <slrnjknrit.1ls.grahn+nntp@frailea.sa.invalid> <9r32s9Fcg8U1@mid.individual.net> <slrnjkqjmv.1ls.grahn+nntp@frailea.sa.invalid>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net tdUbV8a7eOJWYba8akeh+A65mqgUzCCpHcFeyYHes11APkJ7m5
Cancel-Lock sha1:NxU2xR+HkKsEmJRSu3W9JrYEEUU=
User-Agent Mozilla/5.0 (X11; SunOS i86pc; rv:7.0.1) Gecko/20111228 Thunderbird/7.0.1
In-Reply-To <slrnjkqjmv.1ls.grahn+nntp@frailea.sa.invalid>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:14603

Show key headers only | View raw


On 02/29/12 11:02 AM, Jorgen Grahn wrote:
> On Tue, 2012-02-28, Ian Collins wrote:
>> On 02/28/12 09:58 AM, Jorgen Grahn wrote:
>>>
>>> I'm also not sure that I'd prefer finding a null pointer in my array,
>>> compared to finding a nil HomeForSale.
>>
>> Using shared_ptr<T>  removes most of those issues.
>
> I think that last issue is enough for me.
>
>    std::Vector<HomeForSale>  homes = lots_of_homes();
>    assert(!homes.empty());
>    const HomeForSale&  home = homes[0];
>    assert(home.valid());
>
> is not much worse compared to
>
>    std::Vector<shared_ptr<HomeForSale>  >  homes = lots_of_homes();
>    assert(!homes.empty());
>    shared_ptr<HomeForSale>  home = homes[0];
>    assert(home.get());
>
> In both cases I cannot statically know that I can pull a valid home
> from the non-empty vector.

You could prevent default initialisation of the pointer:

#include <vector>
#include <tr1/memory>

struct X {};

struct Ptr : std::tr1::shared_ptr<X>
{
   explicit Ptr( X* x ) : std::tr1::shared_ptr<X>(x) {}

private:
   Ptr() {}
};

int main() {
   std::vector<Ptr> v(10);
}

Which is quite handy.

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

A question on "uncopyable" that disable copy constructor TH <python152@gmail.com> - 2012-02-22 20:45 -0800
  Re: A question on "uncopyable" that disable copy constructor Ian Collins <ian-news@hotmail.com> - 2012-02-23 18:33 +1300
    Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-23 08:47 +0000
      Re: A question on "uncopyable" that disable copy constructor Ian Collins <ian-news@hotmail.com> - 2012-02-26 08:16 +1300
        Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-25 19:49 +0000
          Re: A question on "uncopyable" that disable copy constructor yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-02-27 14:32 +0000
            Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-27 15:54 +0000
              Re: A question on "uncopyable" that disable copy constructor yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-02-27 16:15 +0000
                Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-27 20:58 +0000
                Re: A question on "uncopyable" that disable copy constructor Ian Collins <ian-news@hotmail.com> - 2012-02-28 17:18 +1300
                Re: A question on "uncopyable" that disable copy constructor Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-02-28 00:00 -0500
                Re: A question on "uncopyable" that disable copy constructor Ian Collins <ian-news@hotmail.com> - 2012-02-28 20:09 +1300
                Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-28 21:19 +0000
                Re: A question on "uncopyable" that disable copy constructor Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-03-04 01:05 -0500
                Re: A question on "uncopyable" that disable copy constructor 88888 Dihedral <dihedral88888@googlemail.com> - 2012-03-04 18:01 -0800
                Re: A question on "uncopyable" that disable copy constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-28 22:02 +0000
                Re: A question on "uncopyable" that disable copy constructor Ian Collins <ian-news@hotmail.com> - 2012-02-29 11:15 +1300
  Re: A question on "uncopyable" that disable copy constructor Miles Bader <miles@gnu.org> - 2012-02-23 15:14 +0900
    Re: A question on "uncopyable" that disable copy constructor "T.H." <python152@gmail.com> - 2012-02-23 01:51 -0800
  Re: A question on "uncopyable" that disable copy constructor bartek szurgot <basz@no.spam> - 2012-02-24 17:18 +0100
    Re: A question on "uncopyable" that disable copy constructor Juha Nieminen <nospam@thanks.invalid> - 2012-02-25 19:10 +0000
      Re: A question on "uncopyable" that disable copy constructor Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-02-25 17:45 -0500
        Re: A question on "uncopyable" that disable copy constructor Juha Nieminen <nospam@thanks.invalid> - 2012-02-26 09:38 +0000
          Re: A question on "uncopyable" that disable copy constructor Juha Nieminen <nospam@thanks.invalid> - 2012-02-26 09:42 +0000
          Re: A question on "uncopyable" that disable copy constructor Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-02-27 23:23 -0500
      Re: A question on "uncopyable" that disable copy constructor 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-28 17:01 -0800

csiph-web