Boost logo

Boost :

Subject: Re: [boost] Cxx dual library
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2016-06-06 17:10:38


Le 05/06/2016 à 09:47, Niall Douglas a écrit :
> On 4 Jun 2016 at 21:28, Rob Stewart wrote:
>
>> Edward, you've missed that Vicente doesn't see that importing either a
>> Boost or a Standard Library solution, into a common namespace requires
>> anything more of the user.
>>
>> The user would always use the new, common namespace name for something,
>> regardless of its original namespace. For example, foo::x is the common
>> name, but x may have been introduced into the foo namespace, by a using
>> directive, from the boost or the std namespace.
>>
>> In the end, the user always includes the foo header and uses the foo
>> name. There are no macros in the user's code. Both solutions select one
>> implementation or the other. Yours refers to the namespace of the
>> selected implementation with a macro, while his just uses namespace foo.
> Do you mean an ultra-simplified form of what boost-lite does like
> this:
>
> namespace boost { namespace afio {
> #if BOOST_AFIO_USING_BOOST_THREAD
> namespace stl11 = ::boost;
> #else
> namespace stl11 = ::std;
> #endif
>
> #if BOOST_AFIO_USING_BOOST_FILESYSTEM
> namespace stl1z = ::boost;
> #else
> namespace stl1z = ::std;
> #endif
> } }
>
> This works, but it's quite ungranular e.g. how do you mash up
> Boost.Thread with Std.Atomic? You could enable this at the cost of
> extra typing imposed on the end user like this:
>
> namespace boost { namespace afio { namespace stl {
> #if BOOST_AFIO_USING_BOOST_ATOMIC
> namespace atomic = ::boost;
> #else
> namespace atomic = ::std;
> #endif
>
> #if BOOST_AFIO_USING_BOOST_THREAD
> namespace thread = ::boost;
> #else
> namespace thread = ::std;
> #endif
>
> #if BOOST_AFIO_USING_BOOST_FILESYSTEM
> namespace filesystem = ::boost;
> #else
> namespace filesystem = ::std;
> #endif
> } } }
>
> Now end user code must always write stl::<selector>::<class>. This I
> think would work well enough.
>
> I'll reiterate that boost-lite requires less typing on the end user
> and is much safer and less error prone to use than the above scheme.
> Still, the above works.
>

No boost::thread::csbl doesn't follows the previous schema.
CSBL provides a single interface depending of the conditions.

#ifndef BOOST_CSBL_QUEUE_HPP
#define BOOST_CSBL_QUEUE_HPP

#include <boost/config.hpp>
// MSVC has some trouble instantiating a non_copyable type
//C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\INCLUDE\xmemory0(606) : error C2248:
'non_copyable::non_copyable' : cannot access private member declared in
class 'non_copyable'
//
..\libs\thread\test\sync\mutual_exclusion\queue_views\single_thread_pass.cpp(24)
: see declaration of 'non_copyable::non_copyable'
//
..\libs\thread\test\sync\mutual_exclusion\queue_views\single_thread_pass.cpp(23)
: see declaration of 'non_copyable'
// C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\INCLUDE\xmemory0(605) : while compiling class template member
function 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)'
// with
// [
// _Ty=non_copyable
// ]
#if defined BOOST_THREAD_USES_BOOST_QUEUE || defined
BOOST_NO_CXX11_RVALUE_REFERENCES || (defined _MSC_VER && _MSC_FULL_VER <
180020827)
#ifndef BOOST_THREAD_USES_BOOST_QUEUE
#define BOOST_THREAD_USES_BOOST_QUEUE
#endif
#include <boost/container/queue.hpp>
#else
#include <queue>
#endif

namespace boost
{
   namespace csbl
   {
#if defined BOOST_THREAD_USES_BOOST_QUEUE
     using ::boost::container::queue;

#else
     using ::std::queue;

#endif

   }
}
#endif // header

On the user side

#include <boost/thread/csbl/queue.hpp>

Make use of boost::csbl::queue as you will use std::queue or
boost::container::queue.

That's all.

I'm not trying to shell CSBL as I believe it has the same issues as CXXD
or BoostLite, when several parts of an application make use of boost or
the standard library. Either all parts use CSBL or it doesn't work well,
as we have yet to manage with the interaction of the different
implementations.

An alternative to this design is for the Boost libraries that don't add
anything specific to the standard one to just do this. But Boost
libraries very often have some extension or some differences because
their implementation was done before the standard was closed.

I believe that the minor syntactical differences between boost and std
are annoying and make it difficult to write code that can use boost or
std interchangeably. This is why I was proposing in another thread to
have a fork of the C++11 library ported to C++98. Maybe I'm wrong yet
with the approach.

I wanted just to show it as an alternative design to the macro design
proposed by Edward.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk