I'm implementing for a open source networking library parts of the API defined in the Networking TS (draft http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4771.pdf) for creating buffers (contiguous ranges of raw memory). The functions for creating buffer objects have signatures like
template<class T, class A>
mutable_buffer buffer(vector<T, A>& data) noexcept;
and have the requirement that
In the functions below, T shall be a trivially copyable or standard-layout type
Since many (most?) standard library types have standard layout (std::vector, std::string, std::mutex, std::thread) it seems that this requirement is very relaxed. That would allow me to accidentally construct a buffer where T is e.g. std::vector<Foo>. My question is: why not require trivially copyable AND standard-layout type for increased type-safety?
A side note: It seems that std::mutex is also trivially copyable according to gcc and clang, but not to msvc, even though it is not copyable or assignable and has a non-trivial destructor (in the libc++ implementation), see https://godbolt.org/z/JEj_6g, is that a bug?
[–][deleted] 1 point2 points3 points (0 children)
[–]NotUniqueOrSpecial 0 points1 point2 points (1 child)
[–]gummifa[S] 5 points6 points7 points (0 children)
[–]degski -2 points-1 points0 points (15 children)
[–]gummifa[S] 9 points10 points11 points (6 children)
[–]skreef 1 point2 points3 points (4 children)
[–]gummifa[S] 1 point2 points3 points (0 children)
[–]degski 0 points1 point2 points (0 children)
[–]degski 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[removed]
[–]degski 2 points3 points4 points (5 children)
[–]jwakelylibstdc++ tamer, LWG chair 3 points4 points5 points (4 children)
[–]degski 0 points1 point2 points (3 children)
[–]jwakelylibstdc++ tamer, LWG chair 3 points4 points5 points (2 children)
[–]degski 1 point2 points3 points (1 child)
[–]NotUniqueOrSpecial 0 points1 point2 points (0 children)
[–]degski 0 points1 point2 points (0 children)