r/cpp • • Apr 19 '20

Default function arguments are the devil

https://quuxplusone.github.io/blog/2020/04/18/default-function-arguments-are-the-devil/
90 Upvotes

149 comments sorted by

View all comments

Show parent comment

4

u/NotMyRealNameObv Apr 19 '20
using libns::Seed;
libns::func(Seed{user_seed}, ...);

And if user_seed is already of the correct type, you just get

libns::func(user_seed);

The library author should never force a polluted global namespace on the end user.

-1

u/fransinvodka Apr 19 '20

Two things:

- I dont' want my users to do `using libns::...;` for every strong type my functions might require.

- Normally, user_seed won't be the "correct" type, as I suppose the user would only use the Seed strong type when calling the function.

Maybe give the possibility of doing something like `using namespace libns::all_trong_types_ns;`, but still far from optimal. That's my point against strong types in libraries.