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 1067717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:11:42+00:00 2026-05-16T20:11:42+00:00

Given the below scenario, I’m having a list of item which might be having

  • 0

Given the below scenario, I’m having a list of item which might be having some duplicated item.
I would like to filter the item, to print the only unique item.

Instead of duplicating a list which remove the duplicated item, I tried to insert them into std::set and std::hash_set. Nevertheless, I found no useful example to perform the operation.

Hence I hope to seek your advice on the following code:

#include <list>
//--> A struct to store software name and version
typedef struct tagSWVERStruct{
  TCHAR szSWName[255];
  TCHAR szVersion[255];
}SWVERSIONSTRUCT, *LPSWVERSIONSTRUCT;

//--> A list of struct to store software name and version
typedef std::list<SWVERSIONSTRUCT>  LISTSWVERSION, *PLISTSWVERSION;

void main()
{
  LISTSWVERSION swList;
  SWVERSIONSTRUCT svSW1, svSW2, svSW3, svSW4;
  CString szVersion, szName;

  //Assign value
  _tcscpy_s(svSW1.szSWName, _T("Adapter 1"));
  _tcscpy_s(svSW2.szSWName, _T("Adapter 2"));
  _tcscpy_s(svSW3.szSWName, _T("Adapter 1"));
  _tcscpy_s(svSW4.szSWName, _T("Adapter 3"));
  _tcscpy_s(svSW1.szVersion, _T("1.0.0"));
  _tcscpy_s(svSW2.szVersion, _T("2.0.0"));
  _tcscpy_s(svSW3.szVersion, _T("1.0.0"));
  _tcscpy_s(svSW4.szVersion, _T("3.0.0"));
  swList.push_back(svSW1);
  swList.push_back(svSW2);
  swList.push_back(svSW3);
  swList.push_back(svSW4);

  //print all the item out
  LISTSWVERSION::iterator it = swList.begin();
  for(; it!=swList.end(); ++it){    
    _tprintf(_T("%s version = %s\n"), (*it).szSWName, (*it).szVersion);
  }
}

/*******
Output:  
Adapter 1 version = 1.0.0 
Adapter 2 version = 2.0.0 
Adapter 1 version = 1.0.0 
Adapter 3 version = 3.0.0

Expected Output: 
Adapter 1 version = 1.0.0 
Adapter 2 version = 2.0.0 
Adapter 3 version = 3.0.0
********/
  • 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-16T20:11:42+00:00Added an answer on May 16, 2026 at 8:11 pm

    Removing duplicates is easy, assuming you can modify the sequence.

    First you will need less-than and equality functors:

    struct less_SWVERSIONSTRUCT
    {
      bool operator () (SWVERSIONSTRUCT const & a, SWVERSIONSTRUCT const & b) const
      {
        // Replace this with the appropriate less-than relation for the structure.
        return std::memcmp (&a, &b, sizeof (a)) < 0;
      }
    };
    
    struct eq_SWVERSIONSTRUCT
    {
      bool operator () (SWVERSIONSTRUCT const & a, SWVERSIONSTRUCT const & b) const
      {
        // Replace this with the appropriate equality relation for the structure.
        return std::memcmp (&a, &b, sizeof (a)) == 0;
      }
    };
    

    Then sort the list using the comparator:

    swList.sort (less_SWVERSIONSTRUCT ());
    

    And now remove sequences of duplicate members:

    swList.erase (
        std::unique (swList.begin (), swList.end (), eq_SWVERSIONSTRUCT ()),
        swList.end ());
    

    Done.

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

Sidebar

Related Questions

I Develop a one application which contaion the scenario given below in that Some
I need some clarification how MS-DTC will behave in scenario given below 1) I
Hello friends i am running code given below which contains the setLogTimeEntery function and
I have a table that contains some data given below. It uses a tree
If possible I would prefer a joda or non-joda solution for the scenario below
Overview This is the scenario: I'm given a value which represents a portion of
I am working to extract some content from a web page. Given below is
Where is the proper place to perform validation given the following scenario/code below: In
I have a scenario as given in the below workflow diagram using core service.
Given below is program for encrypting a string. I had taken this code from

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.