Fruitful use of reference

Still new to C++ I try to get used to the kind of reference of this site, for example for unordered map here: http://www.cplusplus.com/reference/unordered_map/unordered_map

Alas, I am stopped brutal too often. At the top I find:
template < class Key,                                    // unordered_map::key_type
           class T,                                      // unordered_map::mapped_type

but no reference, what is allowed as unordered_map::key_type. The TOC on the left side shows only unordered_map::key_eq, but nothing about key_type.

When I use VS2015 and type in a cpp std::unordered_map<std::int a menu pop up and offers int16_t, int32_t, int64_t, and int8_t (and few other entries) -- but I have no clue why there is an "_t" attached to these integer types. And - ...! - where should I have found it within the Reference of this site.

Further down in the description (in fact I hoped to find within Reference a documentation) there is a headline
Container properties
followed by five types, Associative, Unordered, Map, Unique keys, and Allocator-aware. But where do I find how to specifiy one of them?

Is there somewhere a legend how to read the references and how to transliterate the description to some code that compiles? Currently the examples are the most useful for me. Alas, there are some which don't compile under VS2015, for example this in http://www.cplusplus.com/reference/unordered_map/unordered_map/begin/ results in
1>c:\users\michael\documents\visual studio 2015\projects\test\test\test.cpp(12): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)

Sure, you may observe a lot by watching. But I want to go my own way instead of prying what others did.
Last edited on
Hello MikeStgt,

Many parts of C++ are known as a "templated class" or otherwise "templated".

This bit:

template < class Key,                                    // unordered_map::key_type
           class T,                                      // unordered_map::mapped_type
           class Hash = hash<Key>,                       // unordered_map::hasher
           class Pred = equal_to<Key>,                   // unordered_map::key_equal
           class Alloc = allocator< pair<const Key,T> >  // unordered_map::allocator_type
           > class unordered_map;


Is showing all the parameters that can be used in std::unordered_map<> referring to what is between the <>s.

For now the only two parameters you need to worry about are "class key", refereed to most often as (key), and "class T" AKA (value). In normal conservation most people would refer as a "key value" pair.

The hard part to understand is that "key and value" can be any valid variable type.
Although "bool" is not a good choice anything form "char" to "long long" is acceptable along with "std::string" I have even seen "value" as a "std::pait<type, type> name;".

On this page http://www.cplusplus.com/reference/unordered_map/unordered_map/ It starts with a rather generic way of describing the template parameters. The next section "Container properties" is trying to explain what an "unordered map" is. In time this will become easier to understand. The section "Template parameters" is the part you need to focus on because it explains each parameter. May be not well, but in time it will make more sense.

In the section "Member types" the table can be very useful. The first two rows of the table cover what you are using now and of that "type" is the most important part meaning any valid variable type.

Under "Member functions" this is where I go to find examples. A lot of times "(constructor)" is a good place to find an example. In this case there is good information, but not what I wanted, so I went to "size" http://www.cplusplus.com/reference/unordered_map/unordered_map/size/ Line 8 starts with defining the "unordered_map" with the "key" being a "std::string" and the "value" being a "double" The rest of the line is just initializing the map with three elements. It is a decent example of how it is defined.

When I use VS2015 and type in a cpp std::unordered_map<std::int a menu pop up and offers int16_t, int32_t, int64_t, and int8_t (and few other entries) -- but I have no clue why there is an "_t" attached to these integer types. And - ...! - where should I have found it within the Reference of this site.

First off in "std::int" the "std::" is not needed as "int" is one of the built in types that you can just use. The list box is Microsoft's way of trying to be helpful. Most of the time it is useful other times it is just annoying. After a while I learned to ignore it is I did not need it. If you keep typing long enough it goes away. The "_t" part I am not sure about. Either its Microsoft's way of not confusing say "int16" with something else or its Microsoft's way of being different. In the end I believe there is a reason for it.

Container properties
followed by five types, Associative, Unordered, Map, Unique keys, and Allocator-aware. But where do I find how to specify one of them?
You do not. refer to what I said earlier.

Without seeing the actual line of code that goes with this error message It is hard to say what caused this.

The part of the error message
binary '<<': no operator found which takes a right-hand operand of type 'const std::string' The first thing I notice is '<<'. Over time I have learned to go to the top of the file to the "#includes" and make sure I have included "string"

Most of the time the code is posted saying there is an error with and no error message. You have done the opposite hence my possible misunderstanding of the error message.

Sure, you may observe a lot by watching. But I want to go my own way instead of prying what others did.
This is good, but I look back to an online course I took in Python. The person teaching the class provided links and told the student to go look at other peoples code to see what and how they did it. Used properly it is a good learning tool just like truing to read as many posts as you can to see what is said.

Sorry to cut this short, but my fingers are cramping up to the point it is hard to type.

This should answer some and bring more questions. Let me know what you do not understand.

Hope that helps,

Andy
Hello Andy!

Thank you very much for your time to write such a long and detailed answer, very appreciated.

The hard part to understand is that "key and value" can be any valid variable type.
No, that is not so hard, the hard part is, that not every variable type is accepted by the VS2015 compiler, and I can not find a list which variable types are valid.

... it explains each parameter. May be not well, but in time it will make more sense.
In other words, I'll understand it when my routine compiles and works as desired.

In the section "Member types" the table can be very useful. The first two rows of the table cover what you are using now and of that "type" is the most important part meaning any valid variable type.
The first two rows show in column definition the first template parameter (Key) and the second template parameter (T), what is from my point of view rather a description (designation, long name, periphrasis) than a definition (specification, determination) -- because without your hint it would be still obscure for me what types are allowed. Without an unambigous specification I will have a "joyless iterarion between vague reference (for me at least) and intolerant compiler.

The list box is Microsoft's way of trying to be helpful. Most of the time it is useful other times it is just annoying.
Ok, understood.

Without seeing the actual line of code that goes with this error message It is hard to say what caused this.
Ah, sorry. Meanwhile I got over the first hurdle (I hope) and my test currently looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// unordered_map::begin/end example
#include <iostream>
#include <unordered_map>

int main()
{
	std::unordered_map<unsigned, std::string> mymap;
	mymap = { { 0X0004,"ADRFCH" },
	{ 0X0018,"OVRSTK" },
	{ 0X0020,"FCHRTN" },
	{ 0X0026,"X<>ROW" },
	{ 0X002F,"XROW0" },
	{ 0X0031,"XROW10" },
	{ 0X0033,"XROW11" },
	{ 0X0035,"XROW12" },
	{ 0X0037,"XROW13" },
	{ 0X0039,"XROW14" },
	{ 0X003B,"XROW2" },
	{ 0X003B,"XROW3" },
	{ 0X0042,"XROW9" },
	{ 0X0045,"REGADR" },
	{ 0X004C,"ADRGSB" },
	{ 0X004F,"BIGBRC" },
	{ 0X0054,"TONSTF" },
	{ 0X0060,"ROWTBL" },
	{ 0X0071,"TONETC" },
	{ 0X0074,"XROW1" },
	{ 0X007F,"ROW7" },
	{ 0X0081,"XROW5" },
	{ 0X0081,"XROW6" },
	{ 0X0086,"XROW4" },
	{ 0X008B,"MATH" },
	{ 0X0090,"XCUTEB" },
	{ 0X0091,"XCUTB1" },
	{ 0X0098,"RSTKB" },
	{ 0X009B,"RST05" },
	{ 0X009D,"RST10" },
	{ 0X00A2,"ERROF" },
	{ 0X00A5,"NFRNC" },
	{ 0X00AE,"FILLY" },
	{ 0X00B2,"XBAD" },
	{ 0X00B4,"YBAD" }
// in sum nearly 3'000 similar entries
	};

	std::cout << "mymap's buckets contain:\n";
	for (unsigned i = 0; i < mymap.bucket_count(); ++i) {
		std::cout << "bucket #" << i << " contains:";
		for (auto local_it = mymap.begin(i); local_it != mymap.end(i); ++local_it)
			std::cout << " " << local_it->first << ":" << local_it->second;
		std::cout << std::endl;
	}

	return 0;
}

It is a first step for what I'd like to do. Just modified an example from here -- http://www.cplusplus.com/reference/unordered_map/unordered_map/begin
It runs flawlessly under http://cpp.sh/ alas, under VS2015 there are plenty of different errors, worst so far (unstable) Fatal error c1060, the compiler is out of heap space, another one, more stable:
1>c:\users\...\documents\visual studio 2015\projects\test\test\test.cpp(2924): error C2679: binary '=': no operator found which takes a right-hand operand of type 'initializer list' (or there is no acceptable conversion)
or
1>c:\users\...\documents\visual studio 2015\projects\test\test\test.cpp(2937): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
what looks like local_it->second does not return something << likes. Hard cheese.

Over time I have learned to go to the top of the file to the "#includes" and make sure I have included "string"
Thank you, that cured all. Now it compiles free of error. Did I overlook something in the Reference of this site?

This should answer some and bring more questions. Let me know what you do not understand.
Thank you once more, you helped me to get the next hurdle. I am back when I am stuck again. Just to show you for what is it about -- I try to speed up the optional trace ouptut of V41 you find here: http://www.hp41.org/LibView.cfm?Command=Author&AuthorID=3201 (hours for few milliseconds)
closed account (E0p9LyTq)
the VS2015 compiler

Consider getting VS2017, it is free with the Community edition and more compliant with the C++ standard than 2015. C++14 & C++17.

Or wait a bit, VS2019 is soon to be released, 2 April is the current official release date.

2019 will have a Community edition, same as 2015 and 2017 have. Community == free for many users.

VS2015 and VS2017 can "live" side by side, you can have both installed without any conflicts.

VS2019 looks to be the same way, peaceful coexistence with 2015/2017.
Last edited on
Thank you for the info. My next step -- I do get rid of VS2015. Fatal error c1060, the compiler is out of heap space for just few lines of simple code is an unmistakably hint: get rid of it. Hope the descendant are better. (Well, someone told me to use VS2010 for the compiler, VS2015 for its IDE. But for me as beginner it's all the same sauce, a cultural clash for a mainframe dinosaur.)
closed account (E0p9LyTq)
That particular error likely won't be solved updating to 2017 or 2019, you might not have enough installed memory and/or too small a page file, but it is worth a try. Install 2017/19 and try the same code in either IDE.

Whoever told you to use 2010 as "the compiler" doesn't have a clue IMO. An IDE is a compiler, and editor and maybe more in one package. 2017 has an integrated debugger that is, for Windows, one of the best. I haven't used 2015 in quite some time, and hadn't learned how to use a debugger then so can't remember if it had an integrated debugger worth anything or not.

2010 is seriously outdated. IIRC it won't compile C++11 code, so lots of the STL is tossed in the waste bin.

2017 won't compile any C++11 specific code, it defaults to C++14 or later. If your goal is being as up-to-date as possible then it shouldn't be a problem.

I don't remember what language standards 2015 can compile, I stopped using it when 2017 was released.

I'm self-taught with C++/Windows programming, learning from outdated books and websites. It is fun watching code that compiled fine with older compilers suddenly go *BOOM* when a newer language standard is set.

Book code might use std::random_shuffle. I try to compile the code using C++17 and it goes down in flames. std::random_shuffle was deprecated in C++14 and removed in C++17.

OK, so I have to use std::shuffle then. But wait, std::shuffle doesn't use C's rand(), it requires one of <random>'s PRNG engines.

So now if I want a time-based seed I should use <chrono>'s std::system_clock, not C's srand().

Rewriting older code to use updated language features, such as range-based for loops or a container's begin()/end() iterators, is for me a nice way to reinforce the features.
It is fun watching code that compiled fine with older compilers suddenly go *BOOM* when a newer language standard is set.

Completely no understanding. Why? Few month ago someone I e-met in another forum gave me access to his brand new z/VM 7.1 mainframe OS, and I installed a program I compiled several years ago on another machine with VM/ESA at that time -- without the need to compile it on the today's OS, I just copied the "running phase", the module as compiled and linked on the old machine. In addition several interfaces in REXX embedding the machine-independent FORTRAN in the fullscreen CMS environment of VM -- also these interfaces run untouched on the latest OS release. This does not mean that there are no improvements over the years.

This is what I mean with 'clash of the cultures'. I don't like old software suddenly go *BOUM*.

What I've installed on the latest z/VM? A firmware interpreter that runs (besides few others) the old HP-12C on the latest mainframe. Big fun for a hobbyist.
closed account (E0p9LyTq)
Why?

An already compiled program is not source code being compiled now. Totally different animals.

Book (source) code might use std::random_shuffle. I try to compile the code using C++17 and it goes down in flames. std::random_shuffle was deprecated in C++14 and removed in C++17.


std::random_shuffle is not valid in C++17. The function was removed from C++17. Compile as C++17 (or later) and any use of std::random_shuffle now generates an error.

Compile as C++14 and a good compiler will WARN std::random_shuffle is deprecated. It shouldn't be used. The use will still compile.

Compile as C++11 or earlier, not even a warning.
closed account (z05DSL3A)
MikeStgt wrote:
My next step -- I do get rid of VS2015. Fatal error c1060, the compiler is out of heap space for just few lines of simple code is an unmistakably hint: get rid of it.

I think you are asking VS2015 to do something that it doesn't understand and it is trying to process what is left before choking. What does it do with the small section of code you posted here?

What does it do with the small section of code you posted here?

Nothing any more, I uninstalled VS2015. It used up all storage or memory how others say, went in combat with Firefox which of the two shortly came back out of the 'no response hermitage' for a short moment. The complete PC was extremely slow and useless.
Same code under VS2017 compiles smooth, slow, but not jeopardizing the complete PC as VS2015 did. No clue what went wrong, no time left to dig it out.
New issue: VS Community 2017 asks for a license, but the script fails constantly, "$Loader" not defined, I'm told. Constantly means, it does not matter which cookies setting I choose in the browser.
VS Community 2017 is said to be free. Funny kind of free.
closed account (E0p9LyTq)
Do you have a hotmail/live email account? If not get one. That fulfills the license requirement.

I've had a hotmail email account long before I had VS2015 or VS2017. I forgot needing to enter an email account to finish licensing either.

With a free email account VS Community is indeed free. No money out of your pocket.
Last edited on
VS Community is indeed free. No money out of your pocket.

Different understanding, IMO free and at no charge is not the same. Instead of coins they ask for other valuta: data. I shall tell my first name, my last name, daymonthyear of birth, my nationality, and my e-mail address or my phone number. That's too much. This details are sufficent complete that for most persons it would be easy to complement the data with town, street and number of your home. Few years ago a single address in this completeness costed 8 EUR.

When testing period of free VS Community 2017 expires I will uninstall it and look for something else.
Uninstalled VS Community 2017 before it expired. It compiled without error but linking failed and I was not able to bind against the correct lib. Now I give CodeBlocks a try.
closed account (z05DSL3A)
0_o you don't seem to give things much of a chance.

What are you trying to build?
closed account (E0p9LyTq)
I shall tell my first name, my last name, daymonthyear of birth, my nationality, and my e-mail address or my phone number. That's too much.

Only if you do provide the info.

When I licensed my copies of 2015 and 2017 I used a throw-away email account and bogus personal data.

Do you really think MS is going to check that I gave bogus data and fine/sue me?

I don't.

And if they try the info I gave will make it hard for them to track me down. My ISP is the only link. Routed through a VPN.
you don't seem to give things much of a chance.

No, I do not, that's correct. Two reasons: i) what I try is of minor importance, see here:
http://www.cplusplus.com/forum/beginner/250862/#msg1104690
and ii) Dave Hayden solved it alredy, here:
http://www.cplusplus.com/forum/beginner/250862/2/#msg1105168

Now with Dave's solution, I could give up anything C++, but I still like to play a bit with it, nothing special, just get used how to employ C++ favourable like here: http://www.cplusplus.com/forum/beginner/250850/#msg1104645

In addition a thirt reason: The inordinate demand for disk space just to be able to do a little bit C++. And when I press F1 to see an explanation for an error, it is not stored within those several GB of messiness. In comparison, all virtual disks for the simulation of an almost up to date mainframe OS are about 200 MB.
bogus personal data

So did I. And I wondered what funny date of birth was possible until the question popped up, to get my parents give me a permission.

At that point I gave up. No chance to correct something, no way to get over this hurdle. Result: two days later I get a mail, my M$ account is ready to use.
Topic archived. No new replies allowed.