Why does this dependent name lookup find a global identifier instead of the method?

To the best of my knowledge here’s what’s going on. DR228 says: [Voted into WP at April 2003 meeting.] Consider the following example: template<class T> struct X { virtual void f(); }; template<class T> struct Y { void g(X<T> *p) { p->template X<T>::f(); } }; This is an error because X is not a member … Read more

SFINAE and partial class template specializations

I would like to argue that the Standard does not support SFINAE in partial specializations, due to a wording defect. Let’s start with [temp.class.spec.match]: A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list (14.8.2). And, from [temp.deduct], … Read more

How to make Django template raise an error if a variable is missing in context

There is a Django Snippet which provides a solution: # settings.py class InvalidVarException(object): def __mod__(self, missing): try: missing_str=unicode(missing) except: missing_str=”Failed to create string representation” raise Exception(‘Unknown template variable %r %s’ % (missing, missing_str)) def __contains__(self, search): if search==’%s’: return True return False TEMPLATE_DEBUG=True TEMPLATE_STRING_IF_INVALID = InvalidVarException()

Why generic lambdas are allowed while nested structs with templated methods aren’t?

This is core issue 728, which was filed before generic lambdas were a thing. You mentioned generic lambdas and that they were identical to local classes with corresponding member template operator(). However, they actually aren’t, and the differences are related to implementation characteristics. Consider template <typename T> class X { template <typename> void foo() { … Read more

“Permanent” std::setw

Well, it’s not possible. No way to make it call .width each time again. But you can use boost, of course: #include <boost/function_output_iterator.hpp> #include <boost/lambda/lambda.hpp> #include <algorithm> #include <iostream> #include <iomanip> int main() { using namespace boost::lambda; int a[] = { 1, 2, 3, 4 }; std::copy(a, a + 4, boost::make_function_output_iterator( var(std::cout) << std::setw(3) << … Read more

Detect existence of private member

There is indeed a way for non-final non-union class types: namespace detail { struct P {typedef int member;}; template <typename U> struct test_for_member : U, P { template <typename T=test_for_member, typename = typename T::member> static std::false_type test(int); static std::true_type test(float); }; } template <typename T> using test_for_member = std::integral_constant<bool, decltype(detail::test_for_member<T>::test(0)){}>; Demo. The trick is to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)