Boost logo

Boost :

From: Edward Diener (eldiener_at_[hidden])
Date: 2020-12-01 22:01:01


On 12/1/2020 4:36 PM, Kostas Savvidis via Boost wrote:
>
>
>> On Dec 1, 2020, at 22:05, Antony Polukhin via Boost <boost_at_[hidden]> wrote:
>>
>>> My alternative idea of "nice to have" is a single Boost library that can
>>> use either boost or std components in its interface. That's not always
>>> possible to obtain though.
>>
>> I've tried that and it kind of works. There are still problems:
>> * users have to use macro to customize the library
>> * bcp still pulls in the Boost alternatives
>> * code redability suffers from typedefs
>> * you still kind of have two different libraries
>
> Here is a case study. Some while ago I proposed to Steven Watanabe, the maintainer of boost.random
> to produce a version of my MIXMAX random number generator for inclusion.
> The software at that point was plain vanilla C++11.
>
> After a go-ahead from Steven I added a series of boosticisms in order to make the stuff conform to how things were done in boost.random.
> The only sticky point was std:array. I was informed by Steven that the library must work with C++03 and there I had to use boost::array or something else.
> Not wanting to use typedefs and macros such as the below,
>
> #ifndef BOOST_NO_CXX11_HDR_ARRAY
> #include <array>
> #define mixmaxarray std::array
> #else
> #include <boost/array.hpp>
> #define mixmaxarray boost::array
> #endif
> ...#undef mixmaxarray
>
> The other alternative kindly proposed by Steven was:
> namespace boost { namespace random { namespace arrayns = std; } }

I wrote a library called cxx_dual ( https://github.com/eldiener/cxx_dual
) to solve a problem like yours, but it did not meet with general
approval. With cxx_dual your code above could have been:

#include <boost/cxx_dual/array.hpp>
#define mixmaxarray cxxd_array_ns::array

C'est tout !

But that is far too easy <g>.

>
> And yet another suggestion was to turn off inclusion of MIXMAX under C++03, but that required messing with
> [[config.requires cxx11_hdr_array]] in the jamfile for tests which I learned had been a source of problems back in 2016!
> http://boost.2283326.n4.nabble.com/question-regarding-quot-requires-cxx11-hdr-array-quot-clause-in-Jamfile-td4690277.html <http://boost.2283326.n4.nabble.com/question-regarding-quot-requires-cxx11-hdr-array-quot-clause-in-Jamfile-td4690277.html>
>
> So, what was the least disruptive solution? Yes, going with boost::array everywhere.

That certainly works ! But then the end-user who is compiling with C++11
on up in his code and using std::array when he needs a C++ array class
might be a bit piqued that he has to use boost::array in your case. OTOH
if he is compiling with C++11 on up he is probably using std::random
instead of boost::random so your choice is right.


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