On 13.07.2019 18:15, Stefan Ram wrote:
>> have to match the parameter list of f? Or is this really an
>
> Thanks for the responses!
>
> I have observed that
>
> typedef decltype
> ( ::std::bind
> ( ::std::forward< F >( f ),
> ::std::forward< Args >( args )...)) _G;
>
> in the constructor body will detect a wrong number of
> arguments for "f" at a constructor call at compile time
> due to a static assertion
>
> static_assert(sizeof...(_BoundArgs) == sizeof...(_Args))
>
> in ::std::bind in <functional> here. But this will not catch a
> wrong type of an argument. But maybe there are implementations
> of ::std::bind around that will detect this too.
Apparently you're saying that with `std::bind` you can bind an incorrect
type of argument, and not have it checked if you don't try to call the
result functor. That makes sense. A class template can have member
functions that wouldn't compile if they were called.
template< class T >
struct S
{
void foo() { 1*T(); }
};
auto main() -> int
{
S<char*> o;
#ifdef FAIL
o.foo();
#else
(void) o;
#endif
}
If you want an up-front error:
I suggest you just put a call of it in a conditional where it's
guaranteed not executed.
Cheers!,
- Alf