I am trying to replace
template < class T void
set2vector (const set < T &s, vector < T &v)
{
typename set < T >::iterator it;
for (it = s.begin (); it != s.end (); it++) {
v.push_back (*it);
}
}
with
template < class T void
set2vector (const set < T &s, vector < T &v)
{
v.assign(BE(s)) ;
}
but I get a segmentation fault. I am using g++ on Fedora core 4. Aren't
these code segments equivalent?
Jan 8 '07
11 2440
Roland Pibinger wrote:
On Mon, 8 Jan 2007 20:10:54 -0500, "Victor Bazarov" wrote:
>I would guess that the function is for repeated use with already created vector (no need to reconstruct it). The following does the same thing
existingvector. swap(std::vecto r(s.begin(), s.end()));
You cannot use a temporary with vector::swap().
Right. It ought to be the other way around:
std::vector(s.b egin(), s.end()).swap(e xistingvector);
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sylvester Hesp skrev:
"peter koch" <pe************ ***@gmail.comwr ote in message
news:11******** *************@1 1g2000cwr.googl egroups.com...
As Victor already pointed out, assign assigns and does not create new
elements.
I'm sorry but that's just nonsense. The assign function does the same as
it's corresponding constructor in vector, namelijk reconstructing the vector
with the range of elements you've provided.
[snip]
Right. One of the (few) times that Victor was wrong and my appeal to
authority became to strong;-)
/Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cylin |
last post by:
Dear all,
Here is my code.
------------------------------
#include <iostream>
#include <vector>
using namespace std;
class A {
public:
|
by: Michael Hopkins |
last post by:
Hi all
I want to create a std::vector that goes from 1 to n instead of 0 to n-1.
The only change this will have is in loops and when the vector returns
positions of elements etc. I am calling this uovec at the moment (for
Unit-Offset VECtor). I want the class to respond correctly to all usage of
STL containers and algorithms so that it is a transparent replacement for
std:vector.
The options seems to be:
|
by: Bob |
last post by:
Here's what I have:
void miniVector<T>::insertOrder(miniVector<T>& v,const T& item)
{
int i, j;
T target;
vSize += 1;
T newVector;
newVector=new T;
|
by: ahrimen |
last post by:
Hi, First I'll state my over all goal = a text based game with several
rooms that have several exits as my first real program that I've done
without the help of a book.
I can make a normal vector object out of a custom class, I can even use
a single object of a class that has vector data members, but If my
vector object of a custom class has a vector data member my program
crashs not when I instaitant it, but if I try calling any of the...
|
by: Tarun |
last post by:
Hello,
I am facing problem sometimes while I am trying to do push_back on a
vector. Currently I am doing resize of the vector increasing the size
by one and then push_back and seems like the code is working fine.
Is it a better idea to do resize befoire calling push_back?
Regards,
Tarun
| |
by: Chris Roth |
last post by:
vector<doublev1(5,1);
vector<doublev2;
v2 = v1; // 1
v2.assign(v1.begin(),v1.end()); // 2
Are 1 and 2 the same, or are their subtle differences between them.
Which is preferable, if either? And yes, I know I could use the
construction vector<doublev2(v1), but I'm giving an example above.
|
by: meisterbartsch |
last post by:
Hi,
I want to assign predefined vallues to a vector, like:
std::vector<doubletr;
tr={3.36,2.09,1.47,1.1,0.87,0.72};
how do i do this? Am I able to assign values without
using .push_back(); ?
|
by: stephen b |
last post by:
Hi all, personally I'd love to be able to do something like this:
vector<intv;
v.assign(1, 2, 5, 9, 8, 7) etc
without having to manually add elements by doing v = 1, v = 2 ..
etc.
it would make for much more readable code that is faster to write in
some situations. I've not seen this feature documented anywhere
|
by: John Doe |
last post by:
Hi,
I have a static array of struct defined like this :
CViewMgr::ViewInfo g_ViewInfo =
{
{ EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView),
NULL,0, 0 },
{ EWelcomeView, ECreateAndDestroy, IDR_MENU_OKCANCEL,
RUNTIME_CLASS(CWelcomeView), NULL,0, 0 },
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |