473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

method max_size() for map-object (STL) returns -1

Hi!
Code:

std::map<int,MyClass*> m;
int mapsize=m.max_size();

So, mapsize is -1.
Can anyone tell me why?
Compile with g++ 3.2.2 under Linux. Under Windows with MS Compiler
everything is OK (not -1).
PS: for std::vector max_size() returns correct value.
Thanks.

Dec 22 '05 #1
2 1851
"alexey_m" <no*****@no.where> schrieb im Newsbeitrag
news:e8******************************@localhost.ta lkaboutprogramming.com...
Hi!
Code:

std::map<int,MyClass*> m;
int mapsize=m.max_size();

So, mapsize is -1.
Can anyone tell me why?
max_size does not return -1, it returns an unsigned value, which cannot be
negative. But it can be outside the range of an int. Try

std::map<int, MyClass*>::size_type size= m.max_size();
Compile with g++ 3.2.2 under Linux. Under Windows with MS Compiler
everything is OK (not -1).
Incidently the MS compiler returns a value in the range of an int.
PS: for std::vector max_size() returns correct value.


std::map<>::max-size also returns the correct value, but your usage is not
correct.

HTH
Heinz
Dec 22 '05 #2
alexey_m wrote:
Hi!
Code:

std::map<int,MyClass*> m;
int mapsize=m.max_size();

So, mapsize is -1.
Can anyone tell me why?
Compile with g++ 3.2.2 under Linux. Under Windows with MS Compiler
everything is OK (not -1).
PS: for std::vector max_size() returns correct value.
Thanks.


Try this:

<code>
#include <iostream>
#include <map>

using namespace std;

struct MyClass {};
int main()
{
map<int, MyClass*> m;
int n = m.max_size();
cout << "m.max_size(): " << m.max_size() << '\n';
cout << "int n=max_size(): " << n << '\n';
return 0;
}
</code>

Nothing more to say, I guess...
Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Dec 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Murat Tasan | last post by:
i am implementing a custom version of the java.util.Map interface. my custom version does some encryption stuff when making modifications to the map via one of the 4 modification methods (put,...
2
by: Alex Vinokur | last post by:
========================================= Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2 20020927 (prerelease) ========================================= Here is some program...
2
by: Kevin Goodsell | last post by:
I was unable to locate the answer to this question in the (draft) Standard or in The C++ Standard Library (Josuttis). What should occur when one attempts to increase the size of a container beyond...
3
by: Lakesider | last post by:
Hi NG, my problem is: I have a class A with a map on it. There is a public methode "Refresh" for this map. Within A i call a class B (new B). In B I modify some things, that would need to do a...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
7
by: Abhishek Saksena | last post by:
Hi all, Can somebody help me what the bhaviour of front method on an empty map. For some reason calling front on an empty map seems to work with gcc compiler but not with .NET. Abhishek
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
10
by: lamxing | last post by:
Dear all, I've spent a long time to try to get the xmldocument.load method to handle UTF-8 characters, but no luck. Every time it loads a document contains european characters (such as the...
9
by: Mark Szlazak | last post by:
I don't think this is "do-able" but thought I'd better check. Say I want to replace certain names in some source code as long as they are not properties (dot properties) of objects. I could use a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.