How can I echo HTML in PHP?

There are a few ways to echo HTML in PHP. 1. In between PHP tags <?php if(condition){ ?> <!– HTML here –> <?php } ?> 2. In an echo if(condition){ echo “HTML here”; } With echos, if you wish to use double quotes in your HTML you must use single quote echos like so: echo … Read more

std::enable_if to conditionally compile a member function

I made this short example which also works. #include <iostream> #include <type_traits> class foo; class bar; template<class T> struct is_bar { template<class Q = T> typename std::enable_if<std::is_same<Q, bar>::value, bool>::type check() { return true; } template<class Q = T> typename std::enable_if<!std::is_same<Q, bar>::value, bool>::type check() { return false; } }; int main() { is_bar<foo> foo_is_bar; is_bar<bar> bar_is_bar; … Read more

Can a class member function template be virtual?

From C++ Templates The Complete Guide: Member function templates cannot be declared virtual. This constraint is imposed because the usual implementation of the virtual function call mechanism uses a fixed-size table with one entry per virtual function. However, the number of instantiations of a member function template is not fixed until the entire program has … Read more

Check if a class has a member function of a given signature

Here’s a possible implementation relying on C++11 features. It correctly detects the function even if it’s inherited (unlike the solution in the accepted answer, as Mike Kinghan observes in his answer). The function this snippet tests for is called serialize: #include <type_traits> // Primary template with a static assertion // for a meaningful error message … Read more

Derived template-class access to base-class member-data

You can use this-> to make clear that you are referring to a member of the class: void Bar<T>::BarFunc () { std::cout << this->_foo_arg << std::endl; } Alternatively you can also use “using” in the method: void Bar<T>::BarFunc () { using Bar<T>::_foo_arg; // Might not work in g++, IIRC std::cout << _foo_arg << std::endl; } … Read more

What is a nondeduced context?

Deduction refers to the process of determining the type of a template parameter from a given argument. It applies to function templates, auto, and a few other cases (e.g. partial specialization). For example, consider: template <typename T> void f(std::vector<T>); Now if you say f(x), where you declared std::vector<int> x;, then T is deduced as int, … Read more

tech