Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use [[no_unique_address]] when supported for data member of view adaptor? #65

Open
patrickroberts opened this issue Nov 22, 2023 · 1 comment

Comments

@patrickroberts
Copy link

Maybe for compatibility it can be a conditionally defined preprocessor macro such as BOOST_STL_INTERFACES_NO_UNIQUE_ADDRESS?

So something like:

// <boost/stl_interfaces/config.hpp>

#if defined(__has_cpp_attribute)
#    if __has_cpp_attribute(no_unique_address)
#        define BOOST_STL_INTERFACES_NO_UNIQUE_ADDRESS [[no_unique_address]]
#    endif
#endif

#if !defined(BOOST_STL_INTERFACES_NO_UNIQUE_ADDRESS)
#    define BOOST_STL_INTERFACES_NO_UNIQUE_ADDRESS
#endif

and then change the line to

BOOST_STL_INTERFACES_NO_UNIQUE_ADDRESS F f_;

The advantage of this is that if std::is_empty_v<F> then std::is_empty_v<boost::stl_interfaces::adaptor<F>> will also be true, which allows it in turn to be used as a potentially empty data member in another class and not occupy additional address space in the layout.

@patrickroberts
Copy link
Author

If there is a desire to still get EBO when [[no_unique_address]] is not supported, then adaptor<F> can inherit from F when std::is_empty_v<F> and also !std::is_final_v<F>, otherwise EBO isn't possible. But that would require a partial class template specialization, which would be a bit more involved change than the suggestion above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant