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

  • SEARCH
  • Home
  • 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 7182461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:46:31+00:00 2026-05-28T17:46:31+00:00

Only one element in the container can have the key property similar to how

  • 0

Only one element in the container can have the key property similar to how rdbms will not allow you to declare
more than one primary key on a table.
Example follows using a vector ( please consider using any other container ( std or boost ) that can accomplish the task
elegantly.

struct Element
{
  std::wstring val_;
  bool key_;
};
std::vector<Element> v;
Element e1;
e1.val_ = L"Jupiter";
e1.key_ = false;
v.push_back(e1);

Element e2;
e2.val_ = L"Mars";
e2.key_ = true;
v.push_back(e2);

Element e3;
e3.val_ = L"Venus";
e3.key_ = false;
v.push_back(e3);

Element e4;
e4.val_ = L"Venus";
e4.key_ = false;
v.push_back(e4);

Key requirement is that if for example an attempt is made to make e3.key_ = true an exception should be thrown because
e2 (“Mars”) already plays that role

Note that duplicates are allowed in this container.

  • 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-28T17:46:33+00:00Added an answer on May 28, 2026 at 5:46 pm

    If you only want to allow one of them to be a key, I would store the indication of the key separately from the individual items:

    struct column_set {
        std::vector<std::wstring> elements;
        size_t key;
    };
    
    column_set v;
    v.elements.push_back(L"Jupiter");
    v.elements.push_back(L"Mars");
    v.elements.push_back(L"Venus");
    v.elements.push_back(L"Venus");
    v.key = 1;
    

    If you want to, it should be fairly easy to write a little front-end code that acts like an array of bool that will return true for an index equal to the value you’ve give for key, and false for any other value.

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

Sidebar

Related Questions

I have an XML variable with only one element in it. I need to
I've got a problem with slideUp . Only one element (the first one) is
Only one instance of a ScriptManager can be added to the page. this error
Only one instance of a Script Manager can be added to the page. Such
I have one user (only one, all the others are fine) trying to update
I need to have only one button in showConfirmDialog . I tried this: int
I have a container element in which I create on the fly/place() a form,
I have two HTML buttons; one submits a form and one closes the container
I'm trying to create a schema for a <property> element which must have a
I have one std::list<> container and these threads: One writer thread which adds elements

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.