POV-Ray : Newsgroups : povray.beta-test : Beta 37 and C++0x : Re: Beta 37 and C++0x Server Time
2 Jul 2024 13:53:14 EDT (-0400)
  Re: Beta 37 and C++0x  
From: Warp
Date: 5 Jun 2010 10:56:55
Message: <4c0a65b7@news.povray.org>
Chris Cason <del### [at] deletethistoopovrayorg> wrote:
> I've made a change that pulls all the 'using namespace std' and 'using
> namespace boost' out of the source, in favor of a few more specific
> declarations in one header file (appropriately commented as to why):

>   using std::string;
>   using std::vector;
>   using std::list;
>   using std::runtime_error;
>   using boost::shared_ptr;

  That seems like a reasonable solution.

> of course this doesn't fix the problem with VS 2010, because some of its
> header files refer to std::tr1::shared_ptr, so unless we go to the trouble
> of explicitly qualifying shared_ptr everywhere we use it (and then have to
> change that if we ever decide to use the tr1 version instead), it's still
> not going to compile.

  I don't see why not. Unless the VS 2010 header files are putting
std::tr1::shared_ptr in the global namespace (which I assume they aren't),
and given that you have removed the "using namespace std;" and "using
namespace boost;" clauses, I don't see how a name collision can happen
anylonger. The "using boost::shared_ptr;" brings only that one to the
global namespace, not the one in "std::".

  I do think that what you did should fix the problem. (Of course it should
be tested to make sure.)

> if C++ supported template typedefs we could fix it more cleanly that way,
> but currently that's not yet the case.

  One trick sometimes used to get around that problem is to use inheritance
instead:

    template<typename T>
    class MySharedPtr: public boost::shared_ptr<T>
    {
        ...
    };

  Of course the downside of this is that you need to (at least with the
current C++ standard) replicate all the necessary constructors in that
derived class, which would call the base equivalent base class constructors.
(Fortunately the copy constructor, assignment operator and destructor don't
need to be replicated.)

  Such a derived class is quite safe to use in that it will even survive
slicing.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.