Date: Tue, 29 Nov 2022 23:26:31 +0000
On Tue, Nov 29, 2022 at 3:33 PM Arthur O'Dwyer
<arthur.j.odwyer_at_[hidden]> wrote:
>
> This doesn't seem like idiomatic C++ code at all.
Here's another example of what we could do with more extreme template
parameters:
template<text K, typename T>
void Func(T &obj)
{
using namespace K;
::SomeFuncName(obj); // Will always invoke the function at
global scope
SomeFuncName(obj); // Might invoke K::SomeFuncName if it exists
}
Perhaps a 'text' parameter could be restricted to one or more valid
C++ id's separated by zero or more double colons, for example
Func<"::std">(obj);
Func<"boost::asio">(obj);
Or alternatively maybe a 'text' parameter could be much more versatile
and be any string to be copy-pasted into the body of a function, maybe
even something like:
Func<"else if constexpr ( std::is_class_v<T> ) return;">(obj);
I think a lot of people would argue that C++ templates could become
very hairy indeed if we allowed the line immediately above, so perhaps
make it a little more restrictive (i.e. one or more valid C++ id's
separated by zero or more double colons).
<arthur.j.odwyer_at_[hidden]> wrote:
>
> This doesn't seem like idiomatic C++ code at all.
Here's another example of what we could do with more extreme template
parameters:
template<text K, typename T>
void Func(T &obj)
{
using namespace K;
::SomeFuncName(obj); // Will always invoke the function at
global scope
SomeFuncName(obj); // Might invoke K::SomeFuncName if it exists
}
Perhaps a 'text' parameter could be restricted to one or more valid
C++ id's separated by zero or more double colons, for example
Func<"::std">(obj);
Func<"boost::asio">(obj);
Or alternatively maybe a 'text' parameter could be much more versatile
and be any string to be copy-pasted into the body of a function, maybe
even something like:
Func<"else if constexpr ( std::is_class_v<T> ) return;">(obj);
I think a lot of people would argue that C++ templates could become
very hairy indeed if we allowed the line immediately above, so perhaps
make it a little more restrictive (i.e. one or more valid C++ id's
separated by zero or more double colons).
Received on 2022-11-29 23:26:43