C++ std::map equivalent? (An in-order iterable associative container)

Mark Isaacson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 4 14:47:18 PDT 2014


On Sunday, 4 May 2014 at 21:40:04 UTC, bearophile wrote:
> Mark Isaacson:
>
>> 2) Create a wrapper struct that contains key and value and 
>> whose comparison operator is defined only on the key. This 
>> would essentially be doing what the C++ implementation does.
>
> Until we have a tree-based associative map, use a tuple for the 
> key-value and define a "less" template argument like q{a.key < 
> b.key} or q{a[0] < b[0]}.
>
> Bye,
> bearophile

Got it, no native support. Most unfortunate. I've always been 
vehemently against losing self-documentation via the 
std::pair/tuple based solution to the problem. I ended up rolling 
my own solution that lets you give meaningful names to the 
wrapper struct's data members: http://pastebin.com/cKLccqFn

Thanks.


More information about the Digitalmars-d-learn mailing list