Friday, June 9, 2017

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

"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 09 06:51AM -0700

I bought a copy of Intel's C++ Compiler years ago, but have since lost
it. Does anybody know who I could contact, or if I can contact someone,
at Intel to find my order, and download another copy of it? Is there a
specific compiler division or sales division for compilers?
 
Thank you,
Rick C. Hodgin
woodbrian77@gmail.com: Jun 09 08:30AM -0700

On Friday, June 9, 2017 at 8:51:27 AM UTC-5, Rick C. Hodgin wrote:
> it. Does anybody know who I could contact, or if I can contact someone,
> at Intel to find my order, and download another copy of it? Is there a
> specific compiler division or sales division for compilers?
 
Maybe you could contact one of these guys:
http://cppcast.com/2017/04/udit-patidar-anoop-prabha/
 
 
Brian
Ebenezer Enterprises - Enjoying programming again.
http://webEbenezer.net
David Brown <david.brown@hesbynett.no>: Jun 09 09:01PM +0200

>> specific compiler division or sales division for compilers?
 
> Maybe you could contact one of these guys:
> http://cppcast.com/2017/04/udit-patidar-anoop-prabha/
 
As an alternative to bugging people who happen to be Intel C++ Compiler
users, why not simply start at the Intel support page for the compiler,
and work from there?
 
<https://software.intel.com/en-us/c-compilers/ipsxe-support>
 
It took me perhaps 20 seconds to find it, and I didn't even need to use
google.
woodbrian77@gmail.com: Jun 09 04:25PM -0700

On Friday, June 9, 2017 at 2:02:08 PM UTC-5, David Brown wrote:
> > http://cppcast.com/2017/04/udit-patidar-anoop-prabha/
 
> As an alternative to bugging people who happen to be Intel C++ Compiler
> users,
 
They are Intel employees. One of them works on supporting the
Intel C++ compiler.
 
I've never tried that compiler. My question would be if they have
support for string_view yet.
 
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
"Chris M. Thomasson" <invalid@invalid.invalid>: Jun 09 01:22PM -0700

On 6/6/2017 5:55 PM, Chris M. Thomasson wrote:
 
> https://youtu.be/-KfI6qZyoQw?t=1938
 
> It about 32:18 - 32:20
 
> C++, nice. ;^D
 
Fwiw, I love to hear about important projects that use C++ on
supercomputers. Very nice!
 
:^)
Adam Badura <adam.f.badura@gmail.com>: Jun 09 02:33AM -0700

Let's start with a simple enumeration:
 
enum class color {
black,
gray,
white
};
 
Now I would like to have means to name individual enumeration values (convert them to strings). I started with something like:
 
template<color v>
constexpr char enum_value_name;
 
template<>
constexpr char enum_value_name<color::black>[] {"color::black"};
template<>
constexpr char enum_value_name<color::rray>[] {"color::gray"};
template<>
constexpr char enum_value_name<color::white>[] {"color::white"};
 
This works fine and all (g++ -Wall -Wextra -pedantic --std=c++14).
 
I do know this requires to provide the enumeration value as compile time template argument and would be of little use (by its own) in run-time. But firstly, it is easy to write a run-time function with switch-case to cover run-time conversion reusing enum_value_name. Secondly, it goes beyond what I'm interested here about.
 
The problem with this approach is that it doesn't support generalization for other enumeration types. If I would try now to add
 
enum class shape {
triangle,
rectangle,
circle
};
 
there is no way to reuse enum_value_name for naming it.
 
To get around this problem I could use two template arguments:
 
template<typename T, T v>
constexpr char enum_value_name;
 
template<>
constexpr char enum_value_name<color, color::black>[] {"color::black"};
template<>
constexpr char enum_value_name<color, color::gray>[] {"color::gray"};
template<>
constexpr char enum_value_name<color, color::white>[] {"color::white"};
 
template<>
constexpr char enum_value_name<shape, shape::triangle>[] {"shape::triangle"};
template<>
constexpr char enum_value_name<shape, shape::rectangle>[] {"shape::rectangle"};
template<>
constexpr char enum_value_name<shape, shape::circle>[] {"shape::circle"};
 
But this looks much worse. There is significant repetition of information. Present also when you try to use it:
 
std::cout << enum_value_name<shape, shape::rectangle> << std::endl;
 
instead of much simpler:
 
std::cout << enum_value_name<shape::rectangle> << std::endl;
 
What seems to be missing here is auto-deduction of type based on value. The exact feature that we have with function templates
 
template<typename T>
unsigned int foo(T v) { return static_cast<unsigned int>(v); }
 
std::cout << foo(shape::rectangle) << std::endl;
 
So why is it not available for value templates (or type templates just the same…)? Are there technical difficulties? Syntax problems? Or just no one asked for it?
Melzzzzz <Melzzzzz@zzzzz.com>: Jun 09 09:49AM

> };
 
> Now I would like to have means to name individual enumeration values
> (convert them to strings). I started with something like:
 
...
> So why is it not available for value templates (or type templates just
> the same…)? Are there technical difficulties? Syntax problems? Or just
> no one asked for it?
That's what map is for...
 
--
press any key to continue or any other to quit...
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jun 09 07:06PM +0200

On 09-Jun-17 11:33 AM, Adam Badura wrote:
> run-time. But firstly, it is easy to write a run-time function with
> switch-case to cover run-time conversion reusing enum_value_name.
> Secondly, it goes beyond what I'm interested here about.
 
Just define the function in the first place. Much easier. You can even
make it `constexpr`.
 
 
> circle
> };
 
> there is no way to reuse enum_value_name for naming it.
 
That would not be a problem with a function: functions can be overloaded.
 
 
 
> std::cout << enum_value_name<shape::rectangle> << std::endl;
 
> What seems to be missing here is auto-deduction of type based on
> value. The exact feature that we have with function templates
Right. A function would be more practical.
 
 
 
> So why is it not available for value templates (or type templates
> just the same…)? Are there technical difficulties? Syntax problems?
> Or just no one asked for it?
 
Generally it's what you use functions for. But the case of creating a
factory function for a class just to get argument type deduction on
constructor arguments, was so common that reportedly C++17 adds support
for that. With C++17 (hopefully! and probably) a template parameter of a
class can be deduced from a constructor argument.
 
Anyway, the short answer is to use a function, just as you have
indicated yourself multiple times.
 
A longer answer is that you can easily automate the text mappings:
 
 
[File "enum_machinery.hpp":]
---------------------------------------------------------------------
#pragma once
 
template< class Enum >
constexpr inline auto cstring_from( Enum const v )
-> char const*;
 
#define DEFINE_CSTRING_FROM_ENUM( Enum ) \
template<> \
constexpr inline auto cstring_from( Enum const v ) \
-> char const* \
{ \
constexpr char const* const enum_value_names[] = { NAMES }; \
return enum_value_names[int( v )]; \
}
---------------------------------------------------------------------
 
[File "define_enum.hpp":]
---------------------------------------------------------------------
#pragma once
 
#if !(defined( ENUM ) && defined( NAMES ))
# error Define ENUM and NAMES before including this header.

No comments: