s****n 发帖数: 700 | 1 我现在有一个map定义如下
typedef std::map< BookKey, depth_quote, BidRanker > BIDMAP;
我现在想再定义一个map, key是字符,value就是BIDMAP
请问语法上应该如何写呢。
谢谢啦。 |
D*******a 发帖数: 3688 | 2 map
【在 s****n 的大作中提到】 : 我现在有一个map定义如下 : typedef std::map< BookKey, depth_quote, BidRanker > BIDMAP; : 我现在想再定义一个map, key是字符,value就是BIDMAP : 请问语法上应该如何写呢。 : 谢谢啦。
|
d****p 发帖数: 685 | 3 Performance wise, better map< char, BIDMAP& >
otherwise modifying the outter map may trigger value passing of the inner
map a lot of times
【在 D*******a 的大作中提到】 : map
|
t****t 发帖数: 6806 | 4 i think you can't do that. reference type is not assignable or moveable. you
may use pointer type but that's more trouble. you may use shared_ptr<>
though.
for c++0x, your concern doesn't not exist since map<> itself is movable. so
value passing (of map<>) is as efficient as using explicit pointer.
【在 d****p 的大作中提到】 : Performance wise, better map< char, BIDMAP& > : otherwise modifying the outter map may trigger value passing of the inner : map a lot of times
|
d****p 发帖数: 685 | 5 You are right: the mapped type cannot be reference since certain operations
on map element may introduce reference of reference.
So a pointer or wapper reference could be considered. Or use pointer
container.
Admire you are very much c++0x aware when talking any c++ topic :-) Let's
wait for its arrival!
you
so
【在 t****t 的大作中提到】 : i think you can't do that. reference type is not assignable or moveable. you : may use pointer type but that's more trouble. you may use shared_ptr<> : though. : for c++0x, your concern doesn't not exist since map<> itself is movable. so : value passing (of map<>) is as efficient as using explicit pointer.
|
t****t 发帖数: 6806 | 6 you can use 0x in gcc 4.4+, or vc 10(?). not all of them, of course. but
quite a lot is here.
operations
【在 d****p 的大作中提到】 : You are right: the mapped type cannot be reference since certain operations : on map element may introduce reference of reference. : So a pointer or wapper reference could be considered. Or use pointer : container. : Admire you are very much c++0x aware when talking any c++ topic :-) Let's : wait for its arrival! : : you : so
|
s****n 发帖数: 700 | 7 Could u give me an example on how to use the shared_ptr<> ? Is this something similar? |
D*******a 发帖数: 3688 | 8 can't do it because references are unassignable. can use map.
【在 d****p 的大作中提到】 : Performance wise, better map< char, BIDMAP& > : otherwise modifying the outter map may trigger value passing of the inner : map a lot of times
|
h****e 发帖数: 2125 | 9
something similar?
to store in a custom list class that internally holds them in a
std::map. The definition of this map within my list class is:
instances of std::shared_ptr that I add to to m_cvars go out
of scope as soon as the function I happen to be in when I add them
finishes. I've tried multiple ways to do this, including:
minVal, hasMax, maxVal));m_cvars[var_name] = cv;/* AND
*/m_cvars[var_name] = std::make_shared(ARGUMENTS FOR
VARIABLE());
std::shared_ptrs with different ways of adding them to the map, such as:
(var_name, cv));/* AND */m_cvars[var_name].reset(new
Variable(ARGUMENTS));
function I am in, and try to access these variables from another part of
my application, the shared_ptr exists in the map but it no longer points
to a valid Variable. Does anyone know what I am doing wrong?
I'm confused, u asked about creating a map of BIDMAP but now u use
"Variable". is "Variable" same as BIDMAP? this should work under any
circumstances:
"
typedef std::map< BookKey, depth_quote, BidRanker > BIDMAP;
shared_ptr p( new BIDMAP( ... ) );
m_cvars.insert( std::make_pair( String, p ) );
"
【在 s****n 的大作中提到】 : Could u give me an example on how to use the shared_ptr<> ? Is this something similar?
|