Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2024-03-25 10:38:42


On 3/24/24 02:22, Tobias Loew via Boost wrote:
> Am 2024-03-23 15:07, schrieb Дмитрий Архипов via Boost:
>> сб, 23 мар. 2024 г. в 15:52, Tobias Loew via Boost
>> <boost_at_[hidden]>:
>>>
>>> Hi,
>>>
>>> I would like to gauge interest in a library that makes the usage of
>>> flag-like enumerations safer.
>>> The library is called Boost.Flags, and its key features are
>>> ...
>>> Example on Godbolt: https://godbolt.org/z/qbojncnd7
>>
>> From the reading of the docs I gathered that the library relies on
>> operators in the global namespace, rather than using a macro to define
>> operators in an enum's namespace. This has a certain flaw:
>> https://godbolt.org/z/xePjK3es6
>
> The described flaw can be avoided by either including flags.hpp before
> `foobar` or by `using ::operator |` in the enums namespace.
> (https://godbolt.org/z/rT5678n4f)
>
> I could add a macro the enables ADL for the current namespace, e.g.
>
> #define BOOST_FLAGS_ENABLE_ADL_FOR_NS  \
> using ::operator| \
> using ::operator& \
> using ::operator^ \
> ... and so on

I don't really like the idea of operators in the global namespace. I
would rather prefer if the operators were defined in the library's
namespace, and the enablement was always through the macro. Where the
macro would not just import the operators for lookup but also "enable"
them for the given enum.


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