vietjtnguyen / argagg

A simple C++11 command line argument parser
MIT License
224 stars 28 forks source link

fix issue with using operator << on argagg types as generics #39

Open mwaltza opened 3 months ago

mwaltza commented 3 months ago

Prior to this change when trying to compile the following sample code:

#include <iostream>

template<typename T>
void logGeneric(T param) {
    std::cout << param << std::endl;
}

#include "include/argagg/argagg.hpp"

int main() {
    argagg::parser argParser{{{"help", {"-h", "--help"}, "Shows this help message.", 0}}};
    logGeneric<argagg::parser>(argParser);
    return 0;
}

I get this:

argagg % g++ --std=c++11 main.cpp 
main.cpp:6:15: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup
    std::cout << param << std::endl;
              ^
main.cpp:13:5: note: in instantiation of function template specialization 'logGeneric<argagg::parser>' requested here
    logGeneric<argagg::parser>(argParser);
    ^
./include/argagg/argagg.hpp:1692:15: note: 'operator<<' should be declared prior to the call site or in namespace 'argagg'
std::ostream& operator << (std::ostream& os, const argagg::parser& x)
              ^
1 error generated.

This change fixes the issue.