EmptyCrate

About Me | Contact Me | Training | C++ Weekly (YouTube) | Awesome C++ T-Shirts

Posts Tagged with Templates

Destructuring Standard Containers in C++17

  1. 2016年09月14日
  2. C++
  3. C++ Weekly
  4. C++17
  5. Templates

A comment was made on my YouTube channel that destructuring in C++17 would be much more useful if it worked with standard containers. At the moment I responsed that this would be someone impossible to get right without adding too much overhead.



C++ Weekly - Ep13 Fibonacci: You're Doing It Wrong

  1. 2016年05月30日
  2. C++
  3. C++ Weekly
  4. Fibonacci
  5. Templates
  6. constexpr

Many of the different ways you might implement a Fibonacci sequence in C++ plus one you’ve probably never considered.



Folds (ish) In C++11

  1. 2016年05月14日
  2. C++
  3. Templates

It is possible to perform some form of the variadic folds that are coming in C++17 with the C++11 and C++14 compilers that we have available today by using just a little bit of creativity.



C++ Weekly - Ep10 Variadic Expansion Wrap-Up

  1. 2016年05月09日
  2. C++
  3. C++ Weekly
  4. Templates

In this episode Jason wraps up what we’ve learned so far about variadic templates and shows some additional techniques to consider.



C++ Weekly - Ep6 Intro To Variadic Templates

  1. 2016年04月11日
  2. C++
  3. C++ Weekly
  4. Templates

In this episode I give a brief introduction to C++ variadic templates and cover some compile time and runtime performance considerations.



C++ Weekly - Ep4 Variadic Template Refactor

  1. 2016年03月28日
  2. C++
  3. C++ Weekly
  4. Templates


Template Code Bloat Revisited: A Smaller make_shared

  1. 2015年04月27日
  2. C++
  3. Templates

Back in 2008 I wrote an article on template code bloat. In that article I concluded that the use of templates does not necessarily cause your binary code to bloat and may actually result in smaller code! This ended up becoming one of my more significant articles and has been referenced on wikipedia.



C++ Partial Specialization of Templates

  1. 2011年10月16日
  2. C++
  3. Programming
  4. Templates

In this article we are going to introduce the concept of C++ Template Partial Specialization. This is meant to be just a primer on the topic and not exhaustive. The examples here will be used and referenced in later articles. A series of discussions about C++11, now that the language has been finalized, will be coming shortly. In C++ a template class such as this:



When to use class vs. typename in a Template Declaration

  1. 2009年04月15日
  2. Best Practices
  3. C++
  4. Programming
  5. Templates

When declaring a template you can choose either "class" or "typename" for a template parameter. Example:



Project Euler - Problem 1 - Sum All Integers Below 1000 and Divisible By 3 or 5

  1. 2009年04月14日
  2. C++
  3. Programming
  4. Puzzle
  5. Templates

The first Project Euler problem is to calculate the sum of all integers below 1000 which are divisible by either 3 or 5. My solution is implemented entirely in C++ templates. The value is recursively calculated at compile time. The template specialization struct Problem1<0> stops the recursion and returns 0. To compile this code with gcc you must expand the maximum allowed template recursion depth to at least 1000. ` g++ EulerProblem1.cpp -ftemplate-depth-1000`



Simple C++ String Conversions

  1. 2009年03月17日
  2. C++
  3. Programming
  4. Templates

The boost::lexical_cast<> utility is a handy way of converting objects to and from strings, providing a mechanism that many scripting languages have built in. lexical_cast works with any C++ type that has ostream and istream operators defined for it, that is, any object that cout << object; or cin >> object; would work with. This boost facility also does intelligent things such as throwing a bad_cast exception if the operation causes an error flag on the stream to be set. I use boost::lexical_cast<> throughout my code at work for things like serialization of objects for human readable communications. It is also sprinkled liberally throughout my code for handling things like quick debug logging:



Templated Constructors in C++: Using the "explicit" Keyword

  1. 2009年02月12日
  2. C++
  3. Programming
  4. Templates

Sometimes, in the course of C++ template based programming it might be desirable to have a constructor that is templated, like the following contrived exampled:



Swig Starter Kit 0.0.2

  1. 2008年12月01日
  2. C++
  3. Changelog
  4. SWIG
  5. Swig Starter Kit
  6. Templates

Release 0.0.2 of Swig Starter Kit was just released. This release sees the addition of template usage examples, including custom function templates and STL usage. Using a SWIG template declaration we are able to instantiate a specific template and use it from our script code.



Pass By Iterator

  1. 2008年05月20日
  2. C++
  3. Programming
  4. Templates

Pass by iterator is not a new concept, but one that we are going to perhaps give a new name to today and propose as a standard for normal usage. If you take for example the normal way of passing around standard containers:



Nobody Understands C++: Part 5: Template Code Bloat

  1. 2008年05月06日
  2. Articles
  3. C++
  4. Nobody Understands C++
  5. Programming
  6. Templates

On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?" Here are the test cases presented, first without the use of templates, second with the use of templates. Exactly the same functionality and exactly the same code output:



Multithreaded C++: Part 4: Futures and Other Thread Handlers

  1. 2008年04月16日
  2. Articles
  3. C++
  4. Multithreaded C++ Series
  5. RAII
  6. Templates
  7. Threads

We’ve covered the "Assembly Language", "C" and "C++" of the C++ threading world, and now we are going to try and move beyond that.



C++ Mutiple Dispatch!

  1. 2008年04月10日
  2. Boost
  3. C++
  4. Programming
  5. Templates

In my last posting about C++ Multiple Dispatch I wondered if it was really any different than function overloading. I now appreciate that it is something that needs to occur at runtime, not compile time.



Nobody Understands C++: Part 3: Templates

  1. 2008年04月05日
  2. Articles
  3. C++
  4. Nobody Understands C++
  5. Programming
  6. Templates

C++ templates is a huge topic that we will not fully cover here. While we have covered templates in the past, this article will cover the very basics and the reasons why we would want to use templates.



C++ Templates: Euclid's Algorithm

  1. 2008年03月24日
  2. C++
  3. Programming
  4. Templates

A while back I was going though the first chapters of Knuth’s The Art of Computer Programming and came across Euclid’s algorithm for finding the greatest common denominator. I decided to implement the algorithm as a C++ template. Here’s the complete example.



C++ Templates: Using Templates to Generate the Fibonacci Sequence

  1. 2008年03月09日
  2. C++
  3. Programming
  4. Templates

The follow code demonstrates a method for generating the Fibonacci Sequence at compile time. Since the sequence is generated at compile time runtime execution of retrieving a number is constant time.



Boost Preprocessor Metaprogramming and Intro to Templates Revisited

  1. 2007年06月28日
  2. Articles
  3. Boost
  4. C++
  5. Programming
  6. Templates

Say you come up with a clever idea for initializing standard container types (blatantly stolen from the C++0x Initializer List concept). It might looks something like the implementation below:



Automatically Generating Templates with the Boost Preprocessor Metaprogramming Library

  1. 2007年06月02日
  2. Boost
  3. C++
  4. Programming
  5. Templates

boost contains a preprocessor metaprogramming libary. What this means, simply, is that it is possible to write code which generates code. The full docs are here.



Templates in the Real World

  1. 2007年05月26日
  2. C++
  3. Programming
  4. Templates

Let’s say I’m doing some cryptography work. I’ve just received a signed message from another machine and I want to validate the signature. I have a few options:



AltStyle によって変換されたページ (->オリジナル) /