[boost] Dropping support for InPlaceFactory from Optional

2 views
Skip to first unread message

Andrzej Krzemienski via Boost

unread,
Oct 1, 2023, 6:46:41 AM10/1/23
to Boost mailing list, Andrzej Krzemienski
Hi Everyone,
I would like to get the community's advice on removing the support for
InPlaceFactory from Boost.Optional.

The motivation for this is to reduce dependencies among Boost libraries.
Boost.Optional is surprisingly heavy. This is mostly due to the dependency
on InPlaceFactory and OptionalPointee from Boost.Utility.

https://pdimov.github.io/boostdep-report/develop/module-weights.html#weight:12

InPlaceFactory (
https://www.boost.org/doc/libs/1_83_0/libs/utility/doc/html/utility/utilities/in_place_factory.html)
used to be a workaround for the missing "perfect forwarding" in C++03, it
emulated both "universal references" and variadic templates. It is
unnecessary for C++11 where Boost.optional offers a superior interface. But
removing the support for InPlaceFactory would break code for people that
happen to use it. When the user switches to C++11 (C++03 support is
deprecated for Boost.Optional) they should expect their programs to still
compile. But if I remove the InPlaceFactory, it forces the users to change
their code, even if they are already on C++11.

Can InPlaceFactory be moved to a separate library? Or is it so useless now
that it has to be eradicated even at the cost of breaking users' code?

I would welcome any suggestions.

Regards,
&rzej;

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Peter Dimov via Boost

unread,
Oct 1, 2023, 7:05:29 AM10/1/23
to bo...@lists.boost.org, Peter Dimov
Andrzej Krzemienski wrote:
> Hi Everyone,
> I would like to get the community's advice on removing the support for
> InPlaceFactory from Boost.Optional.
>
> The motivation for this is to reduce dependencies among Boost libraries.
> Boost.Optional is surprisingly heavy. This is mostly due to the dependency
> on InPlaceFactory and OptionalPointee from Boost.Utility.
>
> https://pdimov.github.io/boostdep-report/develop/module-weights.html#weight:12
>
> InPlaceFactory (
> https://www.boost.org/doc/libs/1_83_0/libs/utility/doc/html/utility/utilities/in_place_factory.html)
> used to be a workaround for the missing "perfect forwarding" in C++03, it
> emulated both "universal references" and variadic templates. It is
> unnecessary for C++11 where Boost.optional offers a superior interface. But
> removing the support for InPlaceFactory would break code for people that
> happen to use it. When the user switches to C++11 (C++03 support is
> deprecated for Boost.Optional) they should expect their programs to still
> compile. But if I remove the InPlaceFactory, it forces the users to change
> their code, even if they are already on C++11.
>
> Can InPlaceFactory be moved to a separate library? Or is it so useless now
> that it has to be eradicated even at the cost of breaking users' code?

Can you not just forward-declare the two base classes
boost::in_place_factory_base and boost::typed_in_place_factory_base?

Andrey Semashev via Boost

unread,
Oct 1, 2023, 9:17:40 AM10/1/23
to bo...@lists.boost.org, Andrey Semashev
On 10/1/23 13:46, Andrzej Krzemienski via Boost wrote:
> Hi Everyone,
> I would like to get the community's advice on removing the support for
> InPlaceFactory from Boost.Optional.
>
> The motivation for this is to reduce dependencies among Boost libraries.
> Boost.Optional is surprisingly heavy. This is mostly due to the dependency
> on InPlaceFactory and OptionalPointee from Boost.Utility.
>
> https://pdimov.github.io/boostdep-report/develop/module-weights.html#weight:12
>
> InPlaceFactory (
> https://www.boost.org/doc/libs/1_83_0/libs/utility/doc/html/utility/utilities/in_place_factory.html)
> used to be a workaround for the missing "perfect forwarding" in C++03, it
> emulated both "universal references" and variadic templates. It is
> unnecessary for C++11 where Boost.optional offers a superior interface. But
> removing the support for InPlaceFactory would break code for people that
> happen to use it. When the user switches to C++11 (C++03 support is
> deprecated for Boost.Optional) they should expect their programs to still
> compile. But if I remove the InPlaceFactory, it forces the users to change
> their code, even if they are already on C++11.
>
> Can InPlaceFactory be moved to a separate library? Or is it so useless now
> that it has to be eradicated even at the cost of breaking users' code?
>
> I would welcome any suggestions.

From the dependency perspective, I would move in-place factories to
Boost.Optional. I don't think any other library uses it (other than to
initialize a boost::optional), and it seems unlikely that it ever will,
now that we have perfect forwarding.

Regarding potential removal of the feature, I suppose, it's up to you to
decide. I am using it in Boost.Log, but since we're moving to C++11 as a
baseline I could switch to emplace().

However, if you decide to remove it, please provide a deprecation period
so that users have time to switch.

Andrzej Krzemienski via Boost

unread,
Oct 1, 2023, 12:56:12 PM10/1/23
to bo...@lists.boost.org, Andrzej Krzemienski
niedz., 1 paź 2023 o 15:17 Andrey Semashev via Boost <bo...@lists.boost.org>
napisał(a):

Thanks for the feedback.
I can see that Boost.Log includes the factory's header explicitly:
https://github.com/boostorg/log/blob/master/src/setup/filter_parser.cpp#L31

I think I will leave it working forever. If I follow Peter's advice, I can
just *enable* the usage of factories by forward declaring their bases. But
you will not be able to use them until you have included the header from
Boost.Utility.
In fact, it looks like I have already followed this advice:
https://raw.githubusercontent.com/boostorg/optional/develop/include/boost/optional/detail/optional_factory_support.hpp

Regards,
&rzej;

Reply all
Reply to author
Forward
0 new messages