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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:14:40+00:00 2026-05-22T19:14:40+00:00

I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)

  • 0

I have the following problem. Consider the classes

class face {
    virtual std::vector<ptr>& get_vertices(void) const = 0;
};

class triangle : public face {
private:
    std::vector<ptr> vertices;
public:
    std::vector<ptr>& get_vertices(void) const { return vertices; };
};

class quadrilateral : public face {
private:
    std::vector<ptr> vertices;
public:
    std::vector<ptr>& get_vertices(void) const { return vertices; };
};

Obviously, a triangle and quadrilateral will always have 3 and 4 vertices respectively.
Thus, I would like to exchange std::vector by std::array of appropriate size to save the overhead induced by the three additional pointers in std::vector. (This is because I will have millions of faces …) Now, is there a chance to have a common access function in face with std::array as with std::vector above?
With a standard C-array, I would simply return a pointer to the first array entry and its size. Is there a STL-way to do the same or something similar? Or is there any other nice way to achieve this functionality?

Thanks for reading and possibly answering!!
Andreas

  • 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-22T19:14:40+00:00Added an answer on May 22, 2026 at 7:14 pm

    std::arrays of different sizes are different types, so I cannot see any way to do what you want. But what if you return the begin() and end() const iterators to whatever container you hold internally, or an small range object containing both? That way you decouple the size of the container from the interface, leaving it to the implementation.

    EDIT: Just to clarify, in order to hide the data storage representation (in this case, size of the std::array), you will need your own iterator class for face. This is easy to implement in terms of pointers since for each face specialization you know the size, begin and end of the underlying data structure. But you cannot directly use the std::array‘s begin() and end() in the interface, obviously.

    Example:

    This is a quick and dirty example illustrating how to implement part of the forward iterator behaviour using pointers. I use the virtual base class and one of the implementations from OP as starting point. I have also omitted all constructors, assignment operators, etc. It also assumes a class Edge (presumably a 2D or 3D point?).

    class face {
    
    public:
    
      typedef Edge* iterator;
      typedef const Edge* const_iterator;
    
      virtual iterator begin() = 0;
      virtual const_iterator begin() const = 0;
      virtual iterator end() = 0;
      virtual const_iterator end() const = 0;
      virtual size_t size() const = 0;
    
      virtual ~face() {};
    
    };
    
    class triangle : public virtual face {
    
    public :
      virtual iterator begin() {return m_edges.begin();}
      virtual const_iterator begin() const {return m_edges.begin();}
      virtual iterator end() {return m_edges.end();}
      virtual const_iterator end() const {return m_edges.end();}
      virtual size_t size() const {return m_edges.size();}
    
    private:
        std::array<Edge, 3> m_edges;
    

    };

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

Sidebar

Related Questions

Consider the following problem: You have a class 'A' that serves as a base
I have the following problem using template instantiation [*]. file foo.h class Foo {
Consider the following. You have a class that you want to serialize with XmlSerializer
I have the following problem: Let's consider we have #define SET callMe #define COLUMN(x)
I'm writing some Boost.Preprocessor metaprogram, and I have the following problem. Consider the following
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem in my Data Structures and Problem Solving using Java
I have the following problem: I open the dialog, open the SIP keyboard to
I have the following problem. If I query values with a keyfigure which is

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.