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

in_place_init & friends could be constexpr to enforce constant initialization #103

Open
ldionne opened this issue Aug 8, 2022 · 2 comments

Comments

@ldionne
Copy link
Member

ldionne commented Aug 8, 2022

In https://github.com/boostorg/optional/blob/develop/include/boost/optional/optional.hpp#L93-L106, we have:

struct in_place_init_t
{
  struct init_tag{};
  explicit in_place_init_t(init_tag){}
};
const in_place_init_t in_place_init ((in_place_init_t::init_tag()));

struct in_place_init_if_t
{
  struct init_tag{};
  explicit in_place_init_if_t(init_tag){}
};
const in_place_init_if_t in_place_init_if ((in_place_init_if_t::init_tag()));

This results in static initializers in binaries (although trivial ones). Instead, it should be valid to change their definition to the following, which would definitely get rid of static initializers in >= C++11:

struct in_place_init_t
{
  struct init_tag{};
  BOOST_CONSTEXPR explicit in_place_init_t(init_tag){}
};
BOOST_CONSTEXPR_OR_CONST in_place_init_t in_place_init ((in_place_init_t::init_tag()));

struct in_place_init_if_t
{
  struct init_tag{};
  BOOST_CONSTEXPR explicit in_place_init_if_t(init_tag){}
};
BOOST_CONSTEXPR_OR_CONST in_place_init_if_t in_place_init_if ((in_place_init_if_t::init_tag()));
@andry81

This comment was marked as off-topic.

@akrzemi1
Copy link
Member

Implemented in develop.

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

3 participants