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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:33:34+00:00 2026-05-30T17:33:34+00:00

I am using boost::program_options and want to pass domain-like options to my program. Such

  • 0

I am using boost::program_options and want to pass “domain”-like options to my program. Such a domain is simply:

template<typename T>
struct CDomain
{
  CDomain(T min = -1, T max = 1) {_min = min; _max = max;};
  T _min;
  T _max;
};

I have written a custom validator for this option class and that works well. Now as I wanted to add a default value, as in

desc.add_options()("domain", po::value<CDomain<long double> >()->default_value(CDomain<long double>(-1,1)), "domain");

boost::program_options called for an operator<<:

error: no match for ‘operator<<’ in ‘stream << input’

I added this one, but still get the same error message:

template<typename T>
ostream& operator<<(ostream& o, CDomain<T>& d)
{
  return o << "[" << boost::lexical_cast<string>(d._min) << ":" << boost::lexical_cast<string>(d._max) << "]";
}

How can I define operator<< for use with default value output in custom option descriptions?


I did some more investigation. The error occurs in boost/lexical_cast.hpp:1147 In member function bool boost::detail::lexical_stream_limited_src<CharT, Traits, RequiresStringbuffer>::shl_input_streamable(InputStreamable&) [with InputStreamable = const CDomain<long double>, CharT = char, Traits = std::char_traits<char>, bool RequiresStringbuffer = true]:

template<typename InputStreamable>
bool shl_input_streamable(InputStreamable& input)
{
    std::basic_ostream<CharT> stream(&stringbuffer);
    bool const result = !(stream << input).fail();
    start = stringbuffer.pbase();
    finish = stringbuffer.pptr();
    return result && (start != finish);
}

This might be a namespace issue, but moving ostream& operator<<(ostream& o, CDomain<T>& d) into boost::detail didn’t solve the problem.

  • 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-30T17:33:35+00:00Added an answer on May 30, 2026 at 5:33 pm

    Redefine your structure likewise:

    template<typename T>
    struct CDomain
    {
      CDomain(T min = -1, T max = 1) {_min = min; _max = max;};
      T _min;
      T _max;
    
      friend std::ostream& operator << (std::ostream& s, const CDomain& domain)
      {
        so << "[" << boost::lexical_cast<string>(d._min) << ":" << boost::lexical_cast<string>(d._max) << "]"
        return s;
      }
    };
    

    That should fix the issue I believe. Here I see it working (Modifed version to make it work online).

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

Sidebar

Related Questions

I am using boost::program_options like this: namespace po = boost::program_options; po::options_description desc(Options); desc.add_options() (help,?,
I'm using boost::program_options in my program. I want to make a certain flag mandatory.
I want to get started using Boost. I'm programming a C++ program in Visual
I want to read an integer array from console using boost::program_options. The length of
I have some trouble reading from an ini file using boost program options. The
Using Boost Program Options, how do you get the string equivalent of argv[0]?
I'm using Boost Program Options , and it takes quite a while (10 seconds
I'm using Boost Program Options Library to parse the command line arguments. I have
I'm using boost::program_options and it suffers from the same as many other c++ libs,
I am using boost shared pointers in my program, and I have a class

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.