C++ Logo

std-discussion

Advanced search

Physical Unit Types as NTTP

From: Victor Dyachenko <__vic_at_[hidden]>
Date: Thu, 09 Jan 2020 13:20:37 +0300
Hello.

Current requirements in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1907r1.html
make it impossible to use abstract physical unit types
(like described in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1935r1.html)
as an NTTP.

We have such types in stdlib since C++11 - chrono duration
types.

     template<..., auto Timeout>
     class request_response_map
     {
         ...
     public:
         static constexpr auto timeout = Timeout;
         ...
     };

     using std::literals;
     request_response_map<..., 1s> map1;
     request_response_map<..., 500ms> map2;

Currently this doesn't work because std::chrono::duration
has non-public data members (as any other abstract
physical unit type). Why standard layout requirement is
not enough for "structural type"?

Allowing standard layout types instead of types with only
public data members will solve the problem. And I believe
will not be harder to implement in the compilers.

Received on 2020-01-09 04:23:11