mirror of
https://github.com/boostorg/foreach.git
synced 2026-07-21 13:23:39 +00:00
Be const-correct with KeyType in map/pair example
This commit is contained in:
+3
-3
@@ -443,19 +443,19 @@ loop variable is a template. Consider trying to iterate over a `std::map`:
|
||||
std::map<int,int> m;
|
||||
|
||||
// ERROR! Too many arguments to BOOST_FOREACH macro.
|
||||
BOOST_FOREACH(std::pair<int,int> p, m) // ...
|
||||
BOOST_FOREACH(std::pair<const int,int> p, m) // ...
|
||||
|
||||
One way to fix this is with a typedef.
|
||||
|
||||
std::map<int,int> m;
|
||||
typedef std::pair<int,int> pair_t;
|
||||
typedef std::pair<const int,int> pair_t;
|
||||
|
||||
BOOST_FOREACH(pair_t p, m) // ...
|
||||
|
||||
Another way to fix it is to predeclare the loop variable:
|
||||
|
||||
std::map<int,int> m;
|
||||
std::pair<int,int> p;
|
||||
std::pair<const int,int> p;
|
||||
|
||||
BOOST_FOREACH(p, m) // ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user