C++ Logo

std-proposals

Advanced search

Re: Request for opinion: Leaning on strong typing in STL.

From: Lyberta <lyberta_at_[hidden]>
Date: Thu, 23 Jul 2020 00:42:26 +0300
Nikolay Mihaylov:
> Hi
>
> sorry to ask you in this way, but I still do not understand what do you
> exactly propose?
>
> what exactly is std::containers:: ? new namespace where container size_type
> is defined,e.g.
>
> namespace std{
> namespace containers{
> using size_type = std::size_t;
> }
> }
>
> ?

For shallow semantics it will be:

namespace std::containers
{

template <unsigned_integral I>
class size_type
{
 I m_value;
public:
 explicit size_type(I value);
 // ...
};


> also how this will work if std::vector is from std::containers::size_type?
> std::vector<int> v1(std::containers::size_type{42}, 42);

Well, we add ctor that takes std::containers::size_type as the first argument. I guess we can disambiguate the mess of weak
types and strong types by using completely new names for strong types, especially if we redo containers under std::containers.

> e.g. how this can compile - it will be ambiguous:
> std::vector<std::containers::size_type> v1(std::containers::size_type{42},
> 42);

This will not compile because of explicit ctor of std::containers::size_type. And because "int" is not "std::unsigned_integral".
I didn't think the full interface through yet.


Received on 2020-07-22 16:45:52