Sign in to follow this  
arithma

[C++ to C#] mapT*, S

Recommended Posts

Quote:
Original post by arithma

What is the type std::map<T*, S> mapped from the C++ language into in the C# language?
for any real types of T and S (eg. T is int and S is char)


Dictionary<T,S> assuming .NET 2.0 or better.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Quote:
Original post by arithma

What is the type std::map<T*, S> mapped from the C++ language into in the C# language?
for any real types of T and S (eg. T is int and S is char)


Dictionary<T,S> assuming .NET 2.0 or better.


How is the equality handled (how do you specify that the comparison should be made based on the contents or on the reference itself?)

How sure are you of your answer?

Share this post


Link to post
Share on other sites
Quote:
Original post by arithma
Quote:
Original post by Telastyn
Quote:
Original post by arithma

What is the type std::map<T*, S> mapped from the C++ language into in the C# language?
for any real types of T and S (eg. T is int and S is char)


Dictionary<T,S> assuming .NET 2.0 or better.


How is the equality handled (how do you specify that the comparison should be made based on the contents or on the reference itself?)

How sure are you of your answer?

Dictionary is using hashing so while it offers the same functionality as std::map it doesn't offer the same complexity. A closer match would be SortedDictionary or SortedList and it uses the IComparer interface for comparison.

Share this post


Link to post
Share on other sites
Correct me if am wrong, but when map<int*, char> is used, the comparison is done on the pointers themselves rather than the integer values. I believe the comparisons in the .NET Framework are done on the values referenced by the references?

Share this post


Link to post
Share on other sites
Perhaps you could create a small generic class or struct that implements IComparable, and simply holds a reference to the actual object. The implementation of IComparable would specifically do a ReferenceEquals() comparison. Then you could use that as the key for your container.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this