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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:43:39+00:00 2026-05-23T16:43:39+00:00

I read the documentation on visit_each , but can’t really see what exactly it

  • 0

I read the documentation on visit_each, but can’t really see what exactly it does, as well as the general use for it, if every user has to overload it anyways. Someone care to enlighten me?


Edit: Maybe I’m just so confused because the following is the whole content of <boost/visit_each.hpp> and I just don’t see any “magic” there to “visit each subobject”:

namespace boost {
  template<typename Visitor, typename T>
  inline void visit_each(Visitor& visitor, const T& t, long)
  {
    visitor(t);
  }

  template<typename Visitor, typename T>
  inline void visit_each(Visitor& visitor, const T& t)
  {
    visit_each(visitor, t, 0);
  }
}

Maybe someone can give me a concrete example of how this is supposed to look like / work?

  • 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-23T16:43:40+00:00Added an answer on May 23, 2026 at 4:43 pm

    I suspect the important part of that documentation is this line: “Library authors will be expected to add additional overloads that specialize the T argument for their classes, so that subobjects can be visited.” In other words, there is no general use for it, it is just a common name for any visitor-based introspection mechanism. The way it is implemented, something will happen for all types, whether their writers were aware of its existance or not, so you don’t get a compile-time failure.

    It doesn’t seem overly useful to me… practically speaking, it is just an internal function of the boost signals library, but I suppose if you’re using that library anyhow specializing visit_each on your own types wouldn’t hurt.

    They mention finding signals::trackable objects. So presumably, they have provided a couple specializations for their own types within the signals library. Then they have a is_trackable functor. Or something similar.

    struct trackable { };
    
    struct Introspective {
        int a;
        double b;
        trackable c;
    };
    
    struct NotIntrospective {
        int a;
        double b;
        trackable c;
    };
    
    template<typename Visitor, typename T>
    inline void visit_each(Visitor& visitor, const T& t, long) {
      visitor(t);    
    } 
    
    template<typename Visitor>
    inline void visit_each(Visitor& visitor, const Introspective& t, int) {
      visitor(t); //"visits" the object as a whole
    
      //recursively visit the member objects; if unspecialized, will simply call `visitor(x)`
      visit_each(visitor, t.a, 0);
      visit_each(visitor, t.b, 0);
      visit_each(visitor, t.c, 0);
    }
    
    struct is_trackable {
      void operator()(const trackable&) { 
        //Do something
      }
    
      template<typename T>
      void operator()(const T&) { }
    }
    
    int main() {
        Introspective a;
        NotIntrospective b;
        trackable c;
    
        visit_each(is_trackable(), a, 0); //calls specialized version, finds `a.c`
        visit_each(is_trackable(), b, 0); //calls default version, finds nothing
        visit_each(is_trackable(), c, 0); //calls default version, which "visits" the 
                                          //object itself, and finds that it is trackable
    }
    

    The key thing is that visit_each itself doesn’t do any magic, except provide a way for a call to visit_each to not fail to compile on an unrecognized type.

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

Sidebar

Related Questions

I can read the MySQL documentation and it's pretty clear. But, how does one
What does InputStream.available() do in Java ? I read the documentation, but I still
I have looked, searched, and read documentation and can't really find anything about this.
I've read some documentation on what autorelease does and the common use cases. I
I have read the documentation for the CI Caching but still don't understand much
I've looked on Wikipedia, googled it, and read the official documentation, but I still
The documentation of ReaderWriterLockSlim.EnterUpgradeableReadLock says: A thread in upgradeable mode can downgrade to read
I have read documentation about Windows Live API: http://msdn.microsoft.com/en-us/library/bb463989.aspx But how can I retrieve
I am new to OSX user space development. I've read documentation and googled before
I read documentation of cache_lite but couldn't found any option regarding to manage cache

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.