Monday, December 30, 2019

Digest for comp.lang.c++@googlegroups.com - 25 updates in 7 topics

Daniel <danielaparker@gmail.com>: Dec 29 10:20PM -0800

On Saturday, December 28, 2019 at 4:00:59 PM UTC-5, Chris Vine wrote:
 
> visitors for std::visit are reasonably easy to write in C++17.
 
For some definition of easy, for a contrary opinion, see
 
https://bitbashing.io/std-visit.html
 
Do you really find (from https://en.cppreference.com/w/cpp/utility/variant/visit)
 
std::visit([](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, int>)
std::cout << "int with value " << arg << '\n';
else if constexpr (std::is_same_v<T, long>)
std::cout << "long with value " << arg << '\n';
else if constexpr (std::is_same_v<T, double>)
std::cout << "double with value " << arg << '\n';
else if constexpr (std::is_same_v<T, std::string>)
std::cout << "std::string with value " << std::quoted(arg) << '\n';
else
static_assert(always_false<T>::value, "non-exhaustive visitor!");
}, w);
 
to be pleasing to the eye?
 
Daniel
"Öö Tiib" <ootiib@hot.ee>: Dec 30 01:23AM -0800

On Monday, 30 December 2019 08:20:15 UTC+2, Daniel wrote:
> static_assert(always_false<T>::value, "non-exhaustive visitor!");
> }, w);
 
> to be pleasing to the eye?
 
Not too attractive but far better than what was available in C++98.
It is easy to understand why.
 
Types and functions were not made first-class citizens in C++ but kind
of compile-time phenomenon.
 
Compile-time processing was also not made normal like any other
processing in C++ but just accidental possibility using ugly template
hacks.
 
These have been tried to retrofit into C++. However not into
C++ language but by parroting best of those horrid template hacks
into library.
 
Only where even best of programmers could not make it without usage of
preprocessor hacks in C++98 (like range based for, variadic templates
and lambdas) have they added something to core language.
 
Also they next to never cut unfortunate features out of C++.
 
Results are what we see. However a tool is a tool. It must not be
pretty. Important is what can be done with it.
boltar@nowhere.org: Dec 30 10:10AM

On Sun, 29 Dec 2019 21:45:14 +0200
 
>> The whole point of a union is not to save memory, its to write as one type
>> and read as another ,
 
>You wish. However, this is undefined behavior by the standard.
 
Oh dear, someone better tell the authors of the standard unix networking
libraries then. Clearly they have no clue, I mean look at this horror from
net/if.h:
 
struct ifreq {
#ifndef IFNAMSIZ
#define IFNAMSIZ IF_NAMESIZE

No comments: