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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:37:32+00:00 2026-05-26T10:37:32+00:00

a very simplistic (and silly) abstraction of what I’m doing is described below: class

  • 0

a very simplistic (and silly) abstraction of what I’m doing is described below:

class A{
private:
    template <typename InIt>
    A foo(InIt begin, InIt end, A& a) {
        // {begin, ind}  is a datastructure containing all "terms" to search for.
        auto iter(sub.begin());
        auto e(sub.end());
        // search trough all elements in original structure.
        do
            if (FUNC) {
                if (++begin != end) {
                    return iter->foo(begin, end, a.append_values(iter));
                    //append_values appends a copy of the element's values at iter
                    //does not copy the sub "trees" of the element at "iter"
                    //it returns a reference to the appended sub "tree"
                } else {
                    return a;
                }
            }
        } while (++iter != e);
        return a;
    }
};

Sub is a vector containing objects of class “A” – so effectivelly creating a tree-datastructure. FUNC is a function that must be true for the branch to be “added” to the new tree.

What I’m wondering is: how many copys are “created” if, say, the depth (difference between initial begin, end) is “X”. – I’m fearing that for each depth a new copy of “a” is created. This is something I wish to prevent. So should I return by reference? – Or by pointer?

  • 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-26T10:37:33+00:00Added an answer on May 26, 2026 at 10:37 am

    UncleBens indeed gave the correct question I needed to find a “solution”.
    I completely “forgot” you can obviously use arguments-by-reference as output too. I don’t have to return anything as I edit the original “a”, not a copy.

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

Sidebar

Related Questions

Here is a very simplistic example of what I'm trying to do: public class
I'm toying around with a very simplistic sort of process-monitor. Currently, it gets a
All, I'm writing a very simplistic parser with python PLY . It mostly does
I'm currently developing a registration system prototype. It's very simplistic and essentially is just
I've got a very simplistic application: #include <vector> void android_main(struct android_app* state) { }
I have a very simplistic REST service (.NET 3.5) somewhat based on the articles
I have a need for a very simplistic way to keep track of time.
EDIT 1: Can someone please help me create a very very simplistic sample page
This may be very simplistic question but I can't find the answer. I want
I have the following very simplistic implementation for a single linked list in C:

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.