Date: Thu, 9 Jan 2020 17:57:06 +0300
Is it a good idea to use literals of type like std::chrono::duration as
NNTP in C++20? Even if data members would be public, there is an issue that
is_same_v<request_response_map<..., 1s>, request_response_map<...,
1000ms>> == false
On Thu, Jan 9, 2020 at 1:20 PM Victor Dyachenko via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> 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.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
NNTP in C++20? Even if data members would be public, there is an issue that
is_same_v<request_response_map<..., 1s>, request_response_map<...,
1000ms>> == false
On Thu, Jan 9, 2020 at 1:20 PM Victor Dyachenko via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> 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.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
-- Андрей Давыдов
Received on 2020-01-09 08:59:48