Using SFINAE to check for global operator

I should have simply been more faithful to this answer. A working implementation is: namespace has_insertion_operator_impl { typedef char no; typedef char yes[2]; struct any_t { template<typename T> any_t( T const& ); }; no operator<<( std::ostream const&, any_t const& ); yes& test( std::ostream& ); no test( no ); template<typename T> struct has_insertion_operator { static std::ostream … Read more

Can the point-of-instantiation be delayed until the end of the translation unit?

Core Working Group defect report 993 was created to address this issue: 993. Freedom to perform instantiation at the end of the translation unit Section: 14.6.4.1 [temp.point] Status: C++11 Submitter: John Spicer Date: 6 March, 2009[Voted into the WP at the March, 2011 meeting.] The intent is that it is a permissible implementation technique to … Read more

Why is the keyword “typename” needed before qualified dependent names, and not before qualified independent names?

A name in C++ can pertain to three different tiers of entities: Types, values, and templates. struct Foo { typedef int A; // type static double B; // value template <typename T> struct C; // template }; The three names Foo::A, Foo::B and Foo::C are examples of all three different tiers. In the above example, … Read more

C++ template functions overload resolution

The unspecialized function templates are also called the underlying base templates. Base templates can be specialized. The overloading rules to see which ones get called in different situations, are pretty simple, at least at a high level: Nontemplate functions are first-class citizens. A plain old nontemplate function that matches the parameter types as well as … Read more

c++ automatic factory registration of derived types

I use a singleton with a member for registration, basically: template< typename KeyType, typename ProductCreatorType > class Factory { typedef boost::unordered_map< KeyType, ProductCreatorType > CreatorMap; … }; Using Loki I then have something along these lines: typedef Loki::SingletonHolder< Factory< StringHash, boost::function< boost::shared_ptr< SomeBase >( const SomeSource& ) > >, Loki::CreateStatic > SomeFactory; Registration is usually … Read more

JQuery’s $ is in conflict with that of StringTemplate.Net in ASP.Net MVC

You can of course move your js logic into a .js file. But if you want it inline with your StringTemplate views, you can escape it using the \$ construct. In addition, you can simply use the jQuery(“selector”), instead of $(“selector”) construct if you want to avoid the escaping syntax. Here’s a good article on … Read more

When should I use escape and safe in Django’s template system?

Actually, it depends. Django’s templating engine does escaping automatically, so you don’t really need to escape. If you add template filter “safe” like {{c.title|safe}} then you do need to worry about things like html injection, because “safe” marks the string as such and it means that it won’t be escaped. There is also an {% … Read more

tech