cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: rfc: curl_easy_setopt() typechecker

From: Michal Marek <mmarek_at_suse.cz>
Date: Tue, 26 Feb 2008 10:22:26 +0100

Nathan E. Moore wrote:
> --On Monday, February 25, 2008 3:11 PM +0100 Michal Marek <mmarek_at_suse.cz>
> wrote:
>
>> - __builtin_types_compatible_p() only works in C, not C++, so for C++
>> there's no typechecking. Although it might be doable using rtti.
>> - It only works with the not-yet-released gcc 4.3.
>
> Argument type checking for C++ can be done via templates without RTTI or
> any other runtime overhead. This is the basic technique:
...
> template<int t_flag, typename Arg>
> void vawrapper(Arg)
> {
> // need static assert here or you just get an error at link time
> STATIC_ASSERT(false);
> }
>
> template<> void vawrapper<INT_ARG, int>(int) {}
>
> template<> void vawrapper<DOUBLE_ARG, double>(double) {}
>
> template<> void vawrapper<CONST_CHAR_PTR_ARG, char const*>(char const*) {}
>
> #define va(flag, arg) vawrapper<flag>(arg)

Neat :-), we could use something like that then.

Michal
Received on 2008-02-26