Topic: near match


Author: allan_w@my-dejanews.com (Allan W)
Date: Sun, 5 Jan 2003 10:07:44 +0000 (UTC)
Raw View
v.Abazarov@attAbi.com ("Victor Bazarov") wrote
> > No, you're not missing anything.  Exact match (the string
> > literal is of type 'char const *') is ranked higher than
> > a standard conversion (pointer to bool).

rodolfofrino@dodo.com.au ("Rodolfo Frino") wrote
> There's something I don't understand. You mentined a 'pointer to bool'
> but the argument of the first f function (1) is bool,
> Where is this 'pointer to bool' that you're referring to?

Victor didn't mean "pointer to bool." He meant "from pointer, to bool."
He meant:

  An exact match (matching "const char*" with "const char*") is
  ranked higher than a standard conversion (matching "pointer"
  to "bool").

More clear?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rodolfofrino@dodo.com.au ("Rodolfo Frino")
Date: Mon, 6 Jan 2003 19:50:56 +0000 (UTC)
Raw View
I didn't understand the thing about "pointer to bool"   :-)
but now is clear like water, Thank you for the post.

Rodolfo


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rodolfofrino@dodo.com.au ("Rodolfo Frino")
Date: Thu, 2 Jan 2003 04:17:35 +0000 (UTC)
Raw View
> No, you're not missing anything.  Exact match (the string
> literal is of type 'char const *') is ranked higher than
> a standard conversion (pointer to bool).
>
> Why do you think you're missing anything?
There's something I don't understand. You mentined a 'pointer to bool'
but the argument of the first f function (1) is bool,
Where is this 'pointer to bool' that you're referring to?


> >
> > //1
> > void f(bool b)
> > {
> >     ShowMessage("bool");
> > }

Rodolfo

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@attAbi.com ("Victor Bazarov")
Date: Thu, 26 Dec 2002 20:48:10 +0000 (UTC)
Raw View
"Johan Kuipers" <barrel62@yahoo.co.uk> wrote...
> Having the following code:
>
> void f(bool);
> void f(const std::string&);
>
> void g()
> {
>    f("foo");
> }
>
> I would think the std::string(const char *) ctor is a nearer match
> then the bool would be.

Why?

> My compiler (gcc 3.1) calls the f(bool) function.
> Is this standard compliant?

Yes, AFAICT.

> I tried to find this in the standard but could not find it.

Clause 13 contains all the relevant material, IMO.  The standard
conversion (boolean conversion) from a pointer to bool has higher
rank than the user-defined conversion (which is what a construction
of a temporary 'std::string' is).  See 13.3.3.1.2 and 13.3.3.2.

Victor
--
Please remove capital A's from my address when replying by mail


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Ken@Alverson.net ("Ken Alverson")
Date: Thu, 26 Dec 2002 20:48:25 +0000 (UTC)
Raw View
"Johan Kuipers" <barrel62@yahoo.co.uk> wrote in message
news:9659f5cc.0212250317.5db11cce@posting.google.com...
>
> I would think the std::string(const char *) ctor is a nearer match
> then the bool would be.
> My compiler (gcc 3.1) calls the f(bool) function.
> Is this standard compliant?

13.3.3.2.2 When comparing the basic forms of implicit conversion
sequences (as defined in 13.3.3.1)
- a standard conversion sequence (13.3.3.1.1) is a better conversion
sequence than a user defined
conversion sequence or an ellipsis conversion sequence

pointer->bool is a standard conversion, so it wins.

Ken


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rodolfofrino@dodo.com.au ("Rodolfo Frino")
Date: Fri, 27 Dec 2002 21:04:42 +0000 (UTC)
Raw View
Function 2 (const char* a) is always called in this case.
Am i missing something here?
(I'm using C++ Builder 5)

//1
void f(bool b)
{
    ShowMessage("bool");
}

//2
void f(const char* a)
{
    ShowMessage(a);
}

void g()
{
    f("which function is called?");
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    g();
}

Rodolfo

""Victor Bazarov"" <v.Abazarov@attAbi.com> wrote in message
news:v0me0nn1q9nf92@corp.supernews.com...
> "Johan Kuipers" <barrel62@yahoo.co.uk> wrote...
> > Having the following code:
> >
> > void f(bool);
> > void f(const std::string&);
> >
> > void g()
> > {
> >    f("foo");
> > }
> >
> > I would think the std::string(const char *) ctor is a nearer match
> > then the bool would be.
>
> Why?
>
> > My compiler (gcc 3.1) calls the f(bool) function.
> > Is this standard compliant?
>
> Yes, AFAICT.
>
> > I tried to find this in the standard but could not find it.
>
> Clause 13 contains all the relevant material, IMO.  The standard
> conversion (boolean conversion) from a pointer to bool has higher
> rank than the user-defined conversion (which is what a construction
> of a temporary 'std::string' is).  See 13.3.3.1.2 and 13.3.3.2.
>
> Victor
> --
> Please remove capital A's from my address when replying by mail
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]
>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@attAbi.com ("Victor Bazarov")
Date: Fri, 27 Dec 2002 22:24:49 +0000 (UTC)
Raw View
""Rodolfo Frino"" <rodolfofrino@dodo.com.au> wrote...
> Function 2 (const char* a) is always called in this case.
> Am i missing something here?

No, you're not missing anything.  Exact match (the string
literal is of type 'char const *') is ranked higher than
a standard conversion (pointer to bool).

Why do you think you're missing anything?

> (I'm using C++ Builder 5)
>
> //1
> void f(bool b)
> {
>     ShowMessage("bool");
> }
>
> //2
> void f(const char* a)
> {
>     ShowMessage(a);
> }
>
> void g()
> {
>     f("which function is called?");
> }
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>     g();
> }

Victor
--
Please remove capital A's from my address when replying by mail


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: barrel62@yahoo.co.uk (Johan Kuipers)
Date: Thu, 26 Dec 2002 16:41:12 +0000 (UTC)
Raw View
Hello,

and a merry christmas to you all.

Having the following code:

void f(bool);
void f(const std::string&);

void g()
{
   f("foo");
}

I would think the std::string(const char *) ctor is a nearer match
then the bool would be.
My compiler (gcc 3.1) calls the f(bool) function.
Is this standard compliant?

I tried to find this in the standard but could not find it.

- Johan

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ron@sensor.com ("Ron Natalie")
Date: Thu, 26 Dec 2002 19:31:06 +0000 (UTC)
Raw View
"Johan Kuipers" <barrel62@yahoo.co.uk> wrote in message news:9659f5cc.0212250317.5db11cce@posting.google.com...

> I would think the std::string(const char *) ctor is a nearer match
> then the bool would be.
> My compiler (gcc 3.1) calls the f(bool) function.
> Is this standard compliant?
>

Nope.   Any pointer can be implicitly converted to bool.   That's
a STANDARD CONVERSION.   The conversion of const char* to string
is a USER-DEFINED CONVERSION .   A standard conversion sequence
is a better conversion than a user-defined conversion sequence.



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]