Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:18:17+00:00 2026-05-20T10:18:17+00:00

I have some opaque bytes which I want to use in an std::map ,

  • 0

I have some opaque bytes which I want to use in an std::map, both as keys and values. I created a class, OpaqueBytes, which has two (private) members: _data and _size, to store the bytes. My Cocoa background tells me that I would need to implement a hashing function and equality function on the class to use it in a std::map. Problem is, it seems like the STL requires strict weak ordering, based on Can a STL map be used with keys of varying sizes.

I have several questions:

  1. Is my intuition to create a class to represent opaque bytes correct? Is there a class in the STL which already exists to hold opaque bytes? In Cocoa parlance, is there an equivilent to NSData?

  2. How should I implement the ordering of OpaqueBytes? I can’t just compare the bytes using memcmp, because the two byte strings could be of differing length – I wouldn’t want FF EE to be considered equal to FF.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:18:18+00:00Added an answer on May 20, 2026 at 10:18 am

    If you need to use OpaqueBytes as a key you will need a strict comparison. This can be a member function or a non-member function.

    Could use something like this:

    // assumed a friend
    bool operator<( OpaqueBytes const& lhs, OpaqueBytes const& rhs )
    {
       int res = memcmp( lhs._data, rhs._data, std::min(lhs_._size, rhs_._size)  );
       return ( res < 0 ) || ( res == 0 && lhs._size < rhs._size );
    }
    

    You could compare size first, of course. You’d get a different ordering but it would still be strict.

    (I still think, as an aside, that map would be better implemented with a compare function than a less).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some ASP.NET web services which all share a common helper class they
I have one texture that has some portions which are transparent transparent I want
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some kind of test data and want to create a unit test
I have some objects which I draw onto a Canvas as part of a
I have some trivial markup that looks like the following: <li class=someclass> <=% t'model.attr'
i have a input tag which is non editable, but some times i need
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.