develooper Front page | perl.perl6.users | Postings from January 2020

Re: stolen uint's

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
January 29, 2020 19:39
Subject:
Re: stolen uint's
Message ID:
6deccf53-672f-524e-9adc-94a260ad8e89@zoho.com
On 2020-01-29 11:32, Trey Harris wrote:
> On Wed, Jan 29, 2020 at 13:50 ToddAndMargo via perl6-users 
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> 
>     Why don't use use
> 
>     typeMappings[type_index( typeid(char) )] = "char";
> 
> Finally, a definition I can work with...
> 
> We can treat this as a request for typeid(); the mapping creation and 
> lookup is an implementation detail.
> 
> So: the C++ typeid operator works in two modes, static (which happens at 
> compile-time and is inlined) and dynamic (which happens at runtime and 
> is subject to polymorphism). Do you want the static or the dynamic behavior?


I thought that was C not C++, but ...

As variables in Raku get boxed and coerced
all the time, I guess I am asking for dynamic.

I am after what the variable is at the moment I
ask.

Is Raku written in C or C++?

One of the guys on the C group wrote me this:


#include <iostream>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <string>

using namespace std;

int main()
{
     unordered_map<type_index, string> typeMappings;
     typeMappings[type_index( typeid(char) )]               = "char";
     typeMappings[type_index( typeid(unsigned char) )]      = "unsigned 
char";
     typeMappings[type_index( typeid(signed char) )]        = "signed char";
     typeMappings[type_index( typeid(short) )]              = "short";
     typeMappings[type_index( typeid(unsigned short) )]     = "unsigned 
short";
     typeMappings[type_index( typeid(int) )]                = "int";
     typeMappings[type_index( typeid(unsigned int) )]       = "unsigned 
int";
     typeMappings[type_index( typeid(long) )]               = "long";
     typeMappings[type_index( typeid(unsigned long) )]      = "unsigned 
long";
     typeMappings[type_index( typeid(long long) )]          = "long long";
     typeMappings[type_index( typeid(unsigned long long) )] = "unsigned 
long long";
     typeMappings[type_index( typeid(float) )]              = "float";
     typeMappings[type_index( typeid(double) )]             = "double";
     typeMappings[type_index( typeid(long double) )]        = "long double";

     int a, c;
     float b;
     long long d;
     cout << typeMappings[type_index( typeid(a + b) )] << endl;
     cout << typeMappings[type_index( typeid(a + c) )] << endl;
     cout << typeMappings[type_index( typeid(a + d) )] << endl;
}

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About