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

  • Home
  • SEARCH
  • 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 7583375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:39:45+00:00 2026-05-30T18:39:45+00:00

I have two functions that I have overloaded for my debug class: template<class IteratorT>

  • 0

I have two functions that I have overloaded for my debug class:

  template<class IteratorT>
    inline debug&
    operator()(const std::string& name,
               IteratorT begin,
               IteratorT end)
    {
      _stream << indent(internal) << "g< " << name << " : [ ";
      for (auto i = begin; i != end; i++)
        _stream << (*i) << " ";
      _stream << "] >" << std::endl;

      return *this;
    }

And

  inline debug&
  operator()(const std::string& name,
             std::vector<uint8_t>::const_iterator begin,
             std::vector<uint8_t>::const_iterator end)
  {
    _stream << indent(internal) << "u8< " << name << " : [ " << std::hex;
    std::copy(begin, end, std::ostream_iterator<uint32_t>(_stream, " "));
    _stream << "] >" << std::endl;

    return *this;
  }

Here is a snipped of how it’s used:

int main()
{
  debug log;

  std::vector<uint8_t> vec;
  vec.push_back(0xde);
  vec.push_back(0xad);
  vec.push_back(0xc0);
  vec.push_back(0xde);

  log("vec", vec.begin(), vec.end());
}

The output is (since it’s not being printed as hex characters I ommited the unformatted result):

g< "vec" : [ ... ] >

Instead of

u8< "vec" : [ de ad c0 de ] >

For some reason the compiler isn’t picking the correct, overloaded function.

$ g++47 --version
g++47 (GCC) 4.7.0 20120224 (experimental)
  • 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-30T18:39:46+00:00Added an answer on May 30, 2026 at 6:39 pm

    The problem in the code is that overload resolution only considers the arguments to the function and not how the result is going to be used. That means that the expression vec.begin() (conversely vec.end()) only considers that vec is a non-const vector, and it is thus using the non-const version.

    While there is an implicit conversion from std::vector<>::iterator to std::vector<>::const_iterator, this required conversion deems the overload as a worse candidate for resolution than the template function with the type substitution being std::vector<>::iterator.

    As of workarounds, you can overload for both iterator and const_iterator (best solution, as the solution is in just the callee) or you can fix the calls by forcing the vector to be const by means of a cast: static_cast<const std::vector<uint8_T>& >(vec).begin() (which is ugly and requires the fix to be applied in all calls, which is hard to maintain)

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

Sidebar

Related Questions

Assume that I have these two overloaded functions. public static void Main(string[]args) { int
I have a class that has two functions, both of which take a different
I have two functions : void foo(const char * p) and template<size_t T_Size> void
I have two functions that have different enough logic but pretty much the same
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
So I have two jquery functions that bassically do the same, but on 2
I have two functions to add and remove table rows that contain a form
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I am attempting to create an overloaded operator for a matrix class that I
I have a subset of a pointer class that look like: template <typename T>

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.