Skip to content

Instantly share code, notes, and snippets.

View gnarayan81's full-sized avatar

Gopal Narayanan gnarayan81

  • Teledyne LeCroy
  • Chestnut Ridge, NY
View GitHub Profile
#include <thing>
void swap(Type<> i, Type<> j) {
t = i;
i = j;
j = t;
}
RetType<> merge_sort(Array_of_Type<> a, size_of_a) {
if (size_of_a > 1) {
@gnarayan81
gnarayan81 / object_layout.cc
Last active September 8, 2024 00:17
Viewing object layout in clang.
// The intent of this class is to display the layout of an object in
// memory.
// Compile with:
// clang -cc1 -x c++ -v -fdump-record-layouts test.cc -emit-llvm -o /dev/null
//
//
//*** Dumping AST Record Layout
//0 | struct Top
//0 | int a
//| [sizeof=4, dsize=4, align=4
@gnarayan81
gnarayan81 / typename_proscript.cc
Last active August 29, 2015 14:21
The intent of this snippet is to illustrate the use and proscription of the typename keyword.
// The example I've chosen is from here:
// http://en.cppreference.com/w/cpp/language/template_specialization
#include <iostream>
template<class T> // primary template
struct is_void : /*typename*/ std::false_type // Despite having a qualified name, typename is now allowed here.
// It leads to the error, error: keyword 'typename' not allowed in this context (the base class is implicitly a type)
{
struct s
{
};
//----------------------------------------------------------------------
// Type deduction class.
struct s_td { // Do not make this a class template, unless the template
// is necessary for something other than echoval(...)
template <typename K>
void echoval(K&& t) // Universal reference.
{
std::cout << "t = " << t << '\n';
}
};