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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:07:03+00:00 2026-06-04T13:07:03+00:00

I want to have an interface ModelGenerator which has a method generate() that takes

  • 0

I want to have an interface ModelGenerator which has a method generate() that takes an iterable list of Evidence and creates a Model. Using the STL pseudo-duck-typing iterator idiom…

template<class Model>
class ModelGenerator {
  public:
    template<class Iterator>
    virtual bool generate(Iterator begin, Iterator end, Model& model) = 0;
};

But virtual functions can’t be templated. So I have to template the whole class:

template<class Model, class Iterator>
class ModelGenerator {
  public:
    virtual bool generate(Iterator begin, Iterator end, Model& model) = 0;
};

Ideally what I’d like to do is something like this…

template<class Model, class Evidence>
class ModelGenerator {
  public:
    virtual bool generate(iterator<Evidence>& begin,
                          iterator<Evidence>& end,
                          Model& model) = 0;
};

But there is no such interface that iterators inherit from. (The class std::iterator only contains a bunch of typedefs, no methods.)

The only way I can think of doing it is to give ModelGenerator a method addEvidence() which adds them one by one before calling generate(), but then I have to give the ModelGenerator state which is a bit of a pain.

How can I write a virtual method that takes any STL 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-06-04T13:07:05+00:00Added an answer on June 4, 2026 at 1:07 pm

    You seem to need an any_iterator. That’s an iterator that performs type erasure to insulate you from the actual iterator implementation.

    Adobe has an implementation of any_iterator:
    http://stlab.adobe.com/classadobe_1_1any__iterator.html

    Boost has an implementation of any_range:
    http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/ranges/any_range.html

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

Sidebar

Related Questions

I have a method on an interface that looks like this and I want
I have an interface that has about 20 methods (huge). I want to create
Suppose I have Objective C interface SomeClass which has a class method called someMethod
I have an interface that I want to implement in separate classes after doing
I want to have a generic object that implements an interface. I mean if
I have a set of objects that I want to conform to an interface,
I have an object that implements an interface. I want to call on the
Is it possible in PHP 5 to have an interface that has private /
I'm writing a simple plugin based program. I have an interface IPlugin which has
i have simple interface that i want to test it out but i have'nt

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.