Opened 16 years ago

Closed 16 years ago

#719 closed Bugs (Invalid)

problem when using bool type in variant

Reported by: chris_lux Owned by: ebf
Milestone: Component: None
Version: None Severity:
Keywords: Cc:

Description

when bool is used as a type in variant the stream 
output does not work as expected.

i used the latest cvs sources.

example:

// works correct
boost::variant<int, float, std::string> vari_t;

vari_t = "hallo";
std::cout << vari_t << std::endl;

output:
hallo

// works not correct
boost::variant<int, bool, float, std::string> vari_t;

vari_t = "hallo";
std::cout << vari_t << std::endl;

vari_t = true;
std::cout << vari_t << std::endl;

output:
1
1



Change History (1)

comment:1 by ebf, 16 years ago

Status: assignedclosed
Logged In: YES 
user_id=120427

This is not a defect; variant uses normal overload
resolution. Consider the following program:

 #include <iostream>
 #include <string>
 
 void f(std::string x)
 {
    std::cout << "string: " << x << std::endl;
 }
 
 void f(bool x)
 {
    std::cout << "bool: " << x << std::endl;
 }
 
 int main()
 {
    f( "hallo" );
    f( true );
 }

This program when run prints the following output:

 bool: 1
 bool: 1

The surprise you are experiencing is that the conversion
from char* to bool is considered better than from char* to
std::string.

Regards,

Eric
Note: See TracTickets for help on using tickets.