Given the following function templates:
#include <vector>
#include <utility>
struct Base { };
struct Derived : Base { };
// #1
template <typename T1, typename T2>
void f(const T1& a, const T2& b)
{
};
// #2
template <typename T1, typename T2>
void f(const std::vector<std::pair<T1, T2> >& v, Base* p)
{
};
Why is it that the followin...
Hi,
I just noticed a strange behavior with overload resolution.
Assume that I have the following method :
public static void DoSomething<T>(IEnumerable<T> items)
{
// Whatever
// For debugging
Console.WriteLine("DoSomething<T>(IEnumerable<T> items)");
}
Now, I know that this method will often be called with a small numb...
Consider the following minimal example:
#include <iostream>
using namespace std;
class myostream : public ostream {
public:
myostream(ostream const &other) :
ostream(other.rdbuf())
{ }
};
int main() {
cout << "hello world" << endl;
myostream s(cout);
s << "hello world" << endl;
myostr...
In C++0x SFINAE rules have been simplified such that any invalid expression or type that occurs in the "immediate context" of deduction does not result in a compiler error but rather in deduction failure (SFINAE).
My question is this:
If I take the address of an overloaded function and it can not be resolved, is that failure in the im...
Some time ago I read an article that explained several pitfalls of argument dependent lookup, but I cannot find it anymore. It was about gaining access to things that you should not have access to or something like that. So I thought I'd ask here: what are the pitfalls of ADL?
...
I am working with some code that has seven overloads of a function TraceWrite:
void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, string Data = "");
void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, bool LogToFileOnly, string Data = "");
void TraceWrite(string Application, LogLevelENUM L...
I have this class in Scala:
object Util {
class Tapper[A](tapMe: A) {
def tap(f: A => Unit): A = {
f(tapMe)
tapMe
}
def tap(fs: (A => Unit)*): A = {
fs.foreach(_(tapMe))
tapMe
}
}
implicit def tapper[A](toTap: A): Tapper[A] = new Tapper(toTap)
}
Now,
"aaa".tap(_.trim)
doesn't compile,...
Hi,
In below program why does the compiler generate an error for the call to the printMax template function and not the call to the printMaxInts function?
#include <iostream>
template<class A>
void printMax(A a,A b)
{
A c = a>b?a:b;
std::cout<<c;
}
void printMaxInts(int a ,int b)
{
int c = a>b?a:b;
std::cout<<c;
}
int...
Consider the following code (it's a little long, but hopefully you can follow):
class A
{
}
class B : A
{
}
class C
{
public virtual void Foo(B b)
{
Console.WriteLine("base.Foo(B)");
}
}
class D: C
{
public override void Foo(B b)
{
Console.WriteLine("Foo(B)");
}
public void Foo(A a)
{
...
How can I dump candidate functions (or viable functions or best viable functions) for a function invocation?
I know g++ provides an option to dump class hierarchy. (In fact, Visual Studio 2010 provides a similar option, but it's undocumented. I remember reading something about it—maybe in the VC++ team blog—but I can't remember it clea...
This code fragment:
namespace ns
{
struct last;
struct first
{
typedef last next;
};
template <typename T>
struct chain
{
chain<typename T::next> next;
};
template <>
struct chain<last>
{
};
}
using namespace ns;
template <typename T>
void f(const T& x) // #1
...
Hello all,
I saw the following code:
class NullClass {
public:
template<class T> operator T*() const { return 0; }
};
const NullClass NULL;
void f(int x);
void f(string *p);
f(NULL); // converts NULL to string*, then calls f(string*)
Q1> I have problems to understand the following statement
template<class T> operator T*() con...