|
|
Yes, but it depends on the template types of the list and the map. Map contains a pair, so if you want to directly copy the pair it's easy. I'm guessing that's not what you want though. Could be harder if you just want one of the elements of the pair.
#include <string><br />
#include <list><br />
#include <map><br />
#include <algorithm><br />
<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
map<int,string> m;<br />
list<pair<int,string> > l;<br />
m[0] = "zero";<br />
m[1] = "one";<br />
m[2] = "two";<br />
m[3] = "three";<br />
std::copy(m.begin(),m.end(),std::back_inserter(l));<br />
<br />
return 0;<br />
}
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
If you're using an STL implementation with the select2nd SGI extension, then you can extract the values out of the pair easily (the following code example is for gcc):
#include <iostream>
#include <map>
#include <vector>
#include <ext/functional>
#include <algorithm>
using namespace std;
using namespace __gnu_cxx;
int main(int argc,char **argv) {
map<int,int> mint;
mint[0] = 1;
mint[1] = 2;
mint[2] = 3;
vector<int> vals = vector<int>(3);
transform(mint.begin(),mint.end(),vals.begin(),
select2nd<map<int,int>::value_type>());
for (vector<int>::const_iterator iter = vals.begin();
iter != vals.end(); ++iter)
{
cout << *iter << endl;
}
}
I can't check if select2nd is supported in VC's STL implementation right now, sorry
- Mike
|
|
|
|
|
Hello,
Sorry for my english, it's not good.
I Would Like to modify the CRect rcBound pass to OnDraw Function in ActiveX control development, for fix the size of my control in any container.
Help me please.
Thank you.
Guy
|
|
|
|
|
compiling some code with just a few ATL classes ( CAtlString and CAtlArray ), I am running into compiler errors. I am using ATL to avoid MFC, and am running into this converting some XML(CMarkup) code.
The errors are:
<font size="0"><br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(467) : error C2825: 'ETraits::INARGTYPE': cannot form a qualified name<br />
c:\Projects\XML\MarkupATL\Markup.h(130) : see reference to class template instantiation 'ATL::CAtlArray<E,ETraits>' being compiled<br />
with<br />
[<br />
E=CMarkup::ElemPos,<br />
ETraits=CMarkup::ElemPos &<br />
]<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(467) : error C2039: 'INARGTYPE' : is not a member of 'operator``global namespace'''<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(467) : error C2146: syntax error : missing ';' before identifier 'INARGTYPE'<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(468) : error C2825: 'ETraits::OUTARGTYPE': cannot form a qualified name<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(468) : error C2039: 'OUTARGTYPE' : is not a member of 'operator``global namespace'''<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcoll.h(468) : error C2146: syntax error : missing ';' before identifier 'OUTARGTYPE'<br />
</font>
What's going on here? What am I missing in terms of headers?
I include: atlbase.h, atlstr.h, atlcoll.h
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
I need to have a pair of std::string and int as key of the map. But doesn't seems to work. I am using Visual Studio 6.
Here is the test program i am trying
#pragma warning (disable:4786)
#include <iostream>
#include <string>
#include
#include <vector>
using namespace std;
#include <myclass.h>
void main()
{
map< pair<string, int="">, string> test;
CMyClass* c = new CMyClass();
// some useful processing ....
test.insert( pair< pair<string,int>,CMyClass*> > (("hello",35), c));
return;
}
Get folloowing error
error C2275: 'pair<struct std::pair<class="" std::basic_string<char,struct="" std::char_traits<char="">,class std::allocator<char> >,int>,class CMyClass *>' : illegal use of this type as an expression
When i change key from pair<string,int> to something non-pair, it works fine. Any idea? is it doable at all?
TIA
|
|
|
|
|
typedef std::pair<MyFirstType, MySecondType> TMyKey;
typedef std::map<TMyKey, std::string> TMyMap;
//you might need to provide comparison function as well
|
|
|
|
|
Thanks AlexO
Could you please give me a short example on how to define comparison operator
I am a newbie to STL stuff
|
|
|
|
|
The following is just an example, it really depends on what kind of pair you have. The main idea is that std::map uses "<" to sort the entries.
struct comparepairs
{
bool operator()(const TMyKey& left, const TMyKey& right) const
{
if(left.first < right.first)
return true;
else if(left.first == right.first)
return left.second < right.second;
else
return false;
}
};
typedef std::map<TMyKey, std::string, comparepairs> TMyMap;
|
|
|
|
|
Thanks again Alexo.
Still curious why the code i am trying is not working
map< pair<string, int="">, CMyClass*> test;
CMyClass* c;
test.insert( pair< pair<string,int>,CMyClass*> > (("hello",35), c));
is it some wrong syntax i am using?
|
|
|
|
|
pair is a template class, which means it is declared when used
Anonymous wrote:
test.insert( pair< pair,
second usage of pair is wrong because pair without template parameters does not make sense
|
|
|
|
|
It should be
test.insert( pair< pair<string,int>,CMyClass*> > (pair<string,int>("hello",35), c));
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Here is a example that should work. It was a bit hard to read your code before, since all the bits between the < and > were thought to be html tags.
#include <map>
#include <string>
#include <utility>
void main()
{
std::map< std::pair<std::string, int*> , std::string> test;
int *value = new int;
// some useful processing ....
test.insert( std::make_pair( std::make_pair( std::string("hello"), 35), value) );
return;
}
But this is the way I prefer to do it, I find it much tidier:
void main()
{
typedef std::pair<std::string, int*> MyKey;
typedef std::map< MyKey , std::string> MyMap;
MyMap test;
int *value = new int;
// some useful processing ....
test[MyKey("hello", 35)] = value;
return;
}
Hopefully helpful,
Phil
|
|
|
|
|
Check out this article[^] where I cover dialog controls and message handling (link[^] to the relevant section)
--Mike--
"I'm working really, really fast at the moment, so a 3 minute outage becomes, due to time dilation, a 5 minute outage."
-- Chris Manuder, relativistic system administrator
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
I followed the tutorial at the following address...
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q184/6/63.asp&NoWebContent=1
It works great! But I would prefer if the excel menu did not merge with my apps menue. Is there anyway to keep the user from seeing and using the excel menu and tool bars?
In truth what I would prefer to do would be to embed the excel worksheet or spreadsheet into a dialog box like you can with office xp by using the Microsoft Office Spreadsheet 9.0 activeX Control. Does anyone know if this is possible using office 97? I was able to do it in VB, but not in MFC.
Thank you very much.
Mardigin
|
|
|
|
|
I was able to remove the formula bar and the Grid headings with the following code.
app.SetDisplayFormulaBar(FALSE);
Window win = app.GetActiveWindow();
win.SetDisplayHeadings(FALSE);
I still want to remove the "Formatting Toolbar" and all of the menus associated with Excel.
Anyideas.
Classes of interest are --> Menu, MenuBar, MenuBars, MenuItem, MenuItems, Menus, Toolbar, ToolbarButton, ToolbarButtons, Toolbars
Sincerely,
Mardigin
|
|
|
|
|
I realize this issue was addressed a few threads below
this one. However, I have attempted to implement the overloading of the > operator (unsuccessfully) as follows:
<code>
class CSpringNode
{
public:
unsigned int GetOldNodeIndex();
unsigned int EntryTracker;
double ycoord;
double xcoord;
double Energy;
unsigned int NodeIndex;
unsigned int Valence;
CM3DVector2f NodeCoords;
CSpringNode(CM3DVector2f NodeCoords, unsigned int Index);
virtual ~CSpringNode();
bool operator >(const CSpringNode& Node1, const CSpringNode& Node2) const
{
return (Node1.Energy > Node2.Energy);
}
protected:
CSpringNode(){};
private:
unsigned int m_uiOldNodeIndex;
};
</code>
but on compile I get:
--------------------Configuration: Solver2D - Win32 Debug--------------------
Compiling...
Solver2D.cpp
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2804: binary 'operator >' has too many parameters
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2333: '>' : error in function declaration; skipping function body
SpringNode1.cpp
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2804: binary 'operator >' has too many parameters
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2333: '>' : error in function declaration; skipping function body
SpringSolver.cpp
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2804: binary 'operator >' has too many parameters
c:\program files\microsoft visual studio\myprojects\solver2d\springnode1.h(28) : error C2333: '>' : error in function declaration; skipping function body
Generating Code...
Error executing cl.exe.
Creating browse info file...
Solver2D.exe - 6 error(s), 0 warning(s)
I can't seem to spot the error. Any advice?
|
|
|
|
|
Your operator > is a member of the class, so it only takes one parameter (the right-hand side of the comparison). The object on the left-hand side of the comparison is this .
bool operator >(const CSpringNode& rhs) const
{
return (Energy > rhs.Energy);
}
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Michael's answer is correct.
I am not sure about this, but I think you need implement the operator <
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
Yep. All ordering functions in STL are based on operator< .
--
Ich, du, sie, er, es, ihr, sie, Sie.
|
|
|
|
|
Hi
I have a project containing an ATL Simple object,
It's a VC++ server project.
I am using VB6 to connect to the object.
Now I wanted to add more ATL Simple objects.
I used the wizard and marked the new objects with
Dual support.
But when I try to connect with the objects in VB6 I get
an error msg: 430, that the object doesn’t support automation.
What did I do wrong???
Yoav
|
|
|
|
|
Although i'm not a VB programmer it sounds to me that your interface does not inherit from IDispatch (or is not a dispinterface). VB(and scripting languages) need IDispatch to communicate. Check your IDL file to see if this is the case.
|
|
|
|
|
I'm making a hyperlink control which i obviously need to color but i found out that chil controls don't automaticly receive the WM_CTLCOLORSTATIC message so i thought i needed to do this with Message Reflection. I however don't have a clue how to do this except for Notify messages. Can somebody help me out?
|
|
|
|
|
Have you looked into handling the OCM_CTRLCOLORSTATIC message with reflection?
|
|
|
|
|
If I use this, how do I reflect the message from to parrent to the child?
|
|
|
|
|