Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Partial specialization

Now, we are getting to the really interesting part of the C++ template programming—partial template specializations. When a class template is partially specialized, it remains as generic code, but less generic than the original template. The simplest form of the partial template is one where some of the generic types are replaced by concrete types, but other types remain generic:

template <typename N, typename D>class Ratio {    .....};template <typename D>class Ratio<double, D> {    public:    Ratio() : value_() {}    Ratio(const double& num, const D& denom) : value_(num/double(denom)) {}    explicit operator double() const { return value_; }    private:    double value_;};

Here, we convert the Ratio to a double value if the numerator ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content