Wednesday, 15 January 2014

stdmap - c++ map containing a list -



stdmap - c++ map containing a list -

i create map key int, , value list of arrays (int[][]).

i tried :

const int r = 4, c = 5; std::map<int, std::list<int[r][c]> > s;

but won't compile , don't understand why ... (r , c parameter of programme not alter during execution).

arrays not re-create constructable or re-create assignable, element of standard container must be. code compile is, array type breaks requirements standard containers , you'll run undefined behaviour. can't have std::list<int[r][c]>. however, c++11 provides nice new compile-time constant sized std::array pleasure:

typedef std::array<std::array<int, c>, r> array_2d; typedef std::list<array_2d> array_list; std::map<int, array_list> s;

otherwise, other alternatives utilize std::vector instead of std::array (preferred), or have std::list of int** , dynamically allocate 2d arrays.

however, i'd consider bit of rethink of design. construction want? should of info grouped struct?

c++ stdmap stdlist

No comments:

Post a Comment