473,804 Members | 3,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vector : reserve(LONG_MA X)


Method vector.reserve( ) returns no value.
How can we prevent the following situation?

====== foo.cpp ======
#include <climits>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
vector<int> v (100e);
cout << v.capacity() << endl;
v.reserve(LONG_ MAX);
cout << v.capacity() << endl;
return 0;
}
=============== ======

====== Compilation & Run ======

$ g++ -v
[---omitted---]
gcc version 3.3.1 (cygming special)

$ g++ -W -Wall foo.cpp

$ a
100
Aborted (core dumped)

=============== =============== =

--
Alex Vinokur
mailto:al****@c onnect.to
http://mathforum.org/library/view/10978.html

Jul 22 '05 #1
2 1920
"Alex Vinokur" <al****@big.foo t.com> wrote in message
news:c6******** ****@ID-79865.news.uni-berlin.de...

Method vector.reserve( ) returns no value.
How can we prevent the following situation?

====== foo.cpp ======
#include <climits>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
vector<int> v (100e);
cout << v.capacity() << endl;
v.reserve(LONG_ MAX);
cout << v.capacity() << endl;
return 0;
}
=============== ======

====== Compilation & Run ======

$ g++ -v
[---omitted---]
gcc version 3.3.1 (cygming special)

$ g++ -W -Wall foo.cpp

$ a
100
Aborted (core dumped)


If LONG_MAX > std::vector::ma x_size() with your standard library
implementation it should throw a std::length_err or exception.

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl

Jul 22 '05 #2
Alex Vinokur wrote:

Method vector.reserve( ) returns no value.
How can we prevent the following situation?

====== foo.cpp ======
#include <climits>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
vector<int> v (100e);
cout << v.capacity() << endl;
v.reserve(LONG_ MAX);
cout << v.capacity() << endl;
return 0;
}
=============== ======

====== Compilation & Run ======

$ g++ -v
[---omitted---]
gcc version 3.3.1 (cygming special)

$ g++ -W -Wall foo.cpp

$ a
100
Aborted (core dumped)

=============== =============== =


Catch the exception.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #3

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

Similar topics

10
7261
by: chandra.somesh | last post by:
Hi I recently had to write a small code in a competition ,but my code was rejected cause it failed in 1 of test cases. The problm was .....we are given vector of strings....each string consists of either 1 or 2("12122" 0r "2121" so on..)...i had to find the that string where percentage of '1' is minimum.Now the problem and solution both are trivial but i was told that comparing double with < or > sign doesn't ensure a correct...
6
3813
by: Andre Majorel | last post by:
How do you compute an off_t with overflow detection ? Ideally, the target language is C89/C90 and the target platform is reasonably recent versions of the major Unixen. If there is no practical way to do that without limiting the target platform set to FreeBSD + Linux + NetBSD + OpenBSD or adding the requirement of conformance to some combination of SUS v2, SUS v3 and C99, I'll settle for that. Overflow-safe versions of + and * would...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.