C++11 template new Features-template for variable-length parameters

Source: Internet
Author: User

This feature is very good, directly to the example, if I want to design a class, cachedfetcher internal may use Std::map may also use Std::unordered_map, may be other map, how to design it? It's hard not to c++11 the template before it gets longer. Because the template parameter of map is not only key,value two Ah, there are some default parameters of the templates parameter ...

??

Template<typename _key, TypeName _value,

Template<class _kty, Class _ty, typename...> class _map = std::unordered_map>

Class Cachedfetcher

{

Public

typedef _key Key;

typedef _value Value;

typedef _map<key, value> Map;

typedef typename Map::iterator iterator;

typedef typename Map::const_iterator Const_iterator;

??

Private

Map _map;

};

??

??

??

Another better feature

Template<typename _key, TypeName _value,

Template<class _kty, Class _ty, typename...> class _map = std::map>

Class Lrumap

{

};

Template <typename Key, TypeName Value, typename...>

using Lruhashmap = Lrumap<key, Value, std::unordered_map>;

??

??

A useful feature of the last non-template, the constructor for reusing base classes

??

Class Featurevector:public Vector

{

Public

~featurevector () = default;

Featurevector (featurevector&&) = default;

featurevector& operator = (featurevector&&) = default;

Featurevector (const featurevector&) = default;

featurevector& operator = (const featurevector&) = default;

??

#ifndef Gccxml

Using Vector::vector;

#endif

}

??

C++11 template new Features-template for variable-length parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.