由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 如何在c++里定义一个map of map
相关主题
why int** cannot convert to const int** ?how to proof (转载)
typedef如果python command line positional arguments 里有些是运算,那这种argument 该怎么处理?
为啥允许这样的const设计C的问题,高手请指点
Help: How to pass a cell matrix as a variable in the arguments of a VBA functionregister variable
这个dtor为啥能被调用呢lambda的一个疑问
请教cosnt的使用sql 数据是存在哪里 (转载)
map shared memory to local processc++ typedef 一问
几个C++的问题how to initialize this struct.
相关话题的讨论汇总
话题: map话题: bidmap话题: variable话题: cvars话题: std
进入Programming版参与讨论
1 (共1页)
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?
1 (共1页)
进入Programming版参与讨论
相关主题
how to initialize this struct.这个dtor为啥能被调用呢
为啥有人喜欢把_s结尾的结构typedef成_t结尾的,有讲究么?请教cosnt的使用
about typedefmap shared memory to local process
如何使用这个template?几个C++的问题
why int** cannot convert to const int** ?how to proof (转载)
typedef如果python command line positional arguments 里有些是运算,那这种argument 该怎么处理?
为啥允许这样的const设计C的问题,高手请指点
Help: How to pass a cell matrix as a variable in the arguments of a VBA functionregister variable
相关话题的讨论汇总
话题: map话题: bidmap话题: variable话题: cvars话题: std