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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:17:38+00:00 2026-05-27T22:17:38+00:00

Well I’m currently refactoring a class I made quite a long time ago. The

  • 0

Well I’m currently refactoring a class I made quite a long time ago. The class is a container type.

Many functions can use advantage of the class structure, and are thus implemented as member functions. However it now seems to be a lot of function which seem “the same”, ie a “find” function:

iterator find(ITEM)
const_iterator find(ITEM) const;
iterator find_if(ITEM, PRED)
const_iterator find_if(ITEM, PRED) const;

4 “functions” to describe nearly the same (and code is almost the same in each version). This becomes very tedious when updating the class, I have to make sure each version is upgraded. Is there a manner to handle these things better? Some other function in the class CAN possibly take 2 predicates, and that meant I suddenly had 8 functions to manage.

I tried calling the “non-constant version from the constant version” but that obviously doesn’t work.

So how does one handle these things? Just bite the bullet and write it down?

EDIT: just to inform: my datastructure resembles a “tree”. Each “object” contains the data (which the find searches) and a “list” with sub-trees. The find function works recursive over all subtrees of a tree (and sub-sub trees). – Just like one would expect when searching a tree.

As there isn’t a clear “end” or “start” iterator to such a tree, using std::find doesn’t yield the correct functionality.

  • 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-27T22:17:39+00:00Added an answer on May 27, 2026 at 10:17 pm

    Scott Meyers solved a similar problem in Item 3 of Effective C++ by calling the const version inside the non-const version and then casting the const result back to non-const:

    const_iterator find(const T& value) const
    {
        // actual implementation of find
    }
    
    iterator find(const T& value)
    {
        return const_cast<iterator>(static_cast<const container*>(this)->find(value));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well the problem is quite easy to solve naively in O(n 3 ) time.
Well, my website can not redirect to https://www.facebook.com/QuaFootSpa from http://quafootspa.com/ I have tried redirection
Well I can start the thread when I press togglebutton to ON and it
Well I want to highlight the view so the user can see which item
Well my short and easy to explain explanation can be this. I have 2
Well, the title is quite self-explanatory... Is it possible to set default port number
Well,I have a parent class with a nested class declared in the protected tab
Well this kind of n00b question but I still can't figure it out. I
Well lets say i have this <table class=infoBox> <tr> <td> test </td> <td> <table>
Well, I'm trying to reuse a portion of C# code. It's an abstract class

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.