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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:54:35+00:00 2026-05-22T01:54:35+00:00

I have the following code: typedef boost::variant<LandSearchParameter, WaterSearchParameter> SearchParameter; enum Visibility{ CLEAR, CLOUDY, FOG,

  • 0

I have the following code:

typedef boost::variant<LandSearchParameter, WaterSearchParameter> SearchParameter;

enum Visibility{
    CLEAR,
    CLOUDY,
    FOG,
    SMOKE
};

class DetectionGenerator : public boost::static_visitor<double>{
public:

    DetectionGenerator(const EnvironmentalFactors& factors);

    double operator()(const LandSearchParameter& land, Visibility vis) const;
    double operator()(const WaterSearchParameter& water, Visibility vis) const;

private:

    const EnvironmentalFactors mFactors;
};

but if I try to use it with boost::apply_visitor in the following manner:

SearchParameter param = globeCover.generateSearch(lat, lon, altitude);
Visibility vis = weather.generateVisibility(lat, lon, altitude, bearing);
DetectionGenerator detectGen(envFactors);
double prob = boost::apply_visitor(detectGen, param, vis);

and get the following from gcc:

error: no matching function for call to ‘apply_visitor(const SearchRescue::DetectionGenerator&, const boost::variant<boost::tuples::tuple<double, double, double, double, double, bool, bool, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::tuple<std::size_t, std::size_t, double, double, double, bool, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&, SearchRescue::Visibility)

If I attempt to wrap the Visibility enum within a boost::variant I get the same error only instead of Visibility it reads all that junk above and whatever name I chose for the variant. I’ve read over the docs on boost for binary visitation but I’m at a loss. Due note, all these things are within the same namespace.

Update:

It was my attempt that was the problem. Not shown above was that I had the visitor as a const variable. Once I took the const out of the picture, it compiled. Thank you all for trying to help me out. Wish I could give more upvotes.

  • 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-22T01:54:35+00:00Added an answer on May 22, 2026 at 1:54 am

    @Boaz Yaniv’s answer is 100% correct. The boost::apply_visitor<> docs state directly:

    Overloads accepting two operands invoke the binary function call operator of the given visitor on the content of the given variant operands.

    Yaniv’s suggested approach for remedying that – taking a Visibility object in the visitor’s constructor – is also the proper fix. You indicated that such an approach did not work for you; I’ll warrant that the problem was in your attempt and not in the approach. ;-] Here’s code that compiles:

    #include <boost/variant.hpp>
    
    struct LandSearchParameter { };
    struct WaterSearchParameter { };
    struct EnvironmentalFactors { };
    
    typedef boost::variant<
        LandSearchParameter,
        WaterSearchParameter
    > SearchParameter;
    
    enum Visibility
    {
        CLEAR,
        CLOUDY,
        FOG,
        SMOKE
    };
    
    struct DetectionGenerator : boost::static_visitor<double>
    {
        DetectionGenerator(EnvironmentalFactors const& factors, Visibility vis)
          : mFactors(factors),
            mVis(vis)
        { }
    
        double operator ()(LandSearchParameter const&) const { return 0.; }
        double operator ()(WaterSearchParameter const&) const { return 0.; }
    
    private:
        EnvironmentalFactors mFactors;
        Visibility mVis;
    };
    
    int main()
    {
        SearchParameter param = LandSearchParameter();
        EnvironmentalFactors const envFactors;
        DetectionGenerator const detectGen(envFactors, CLOUDY);
        double const prob = boost::apply_visitor(detectGen, param);
    }
    

    If this approach continues to fail to work for you then you’ll need to edit your question and update it with your actual, current code.

    P.S. Your approach of making Visibility a single-type boost::variant<> should work also, though it seems silly to me. For reference, this compiles:

    #include <boost/variant.hpp>
    
    struct LandSearchParameter { };
    struct WaterSearchParameter { };
    struct EnvironmentalFactors { };
    
    typedef boost::variant<
        LandSearchParameter,
        WaterSearchParameter
    > SearchParameter;
    
    enum VisibilityT
    {
        CLEAR,
        CLOUDY,
        FOG,
        SMOKE
    };
    
    typedef boost::variant<VisibilityT> Visibility;
    
    struct DetectionGenerator : boost::static_visitor<double>
    {
        explicit DetectionGenerator(EnvironmentalFactors const& factors)
          : mFactors(factors)
        { }
    
        double operator ()(LandSearchParameter const&, VisibilityT const) const
        { return 0.; }
    
        double operator ()(WaterSearchParameter const&, VisibilityT const) const
        { return 0.; }
    
    private:
        EnvironmentalFactors mFactors;
    };
    
    int main()
    {
        SearchParameter param = LandSearchParameter();
        EnvironmentalFactors const envFactors;
        DetectionGenerator const detectGen(envFactors);
        Visibility vis = CLOUDY;
        double const prob = boost::apply_visitor(detectGen, param, vis);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code (which largely follows the first example here: http://www.boost.org/doc/libs/1_42_0/libs/multi_index/doc/examples.html )).
I have the following code: #include <iostream> #include boost/unordered_map.hpp using namespace std; using namespace
I have the following code parts: typedef struct Board* BoardP; typedef struct Board {
I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node;
I have my code organized as following class MyClass { public: typedef void (MyClass::Ptr2func)();
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from

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.