Boost :: Iterator

zhaozj2021-02-16  29

Sender: huxw (Mi Duck and Tang Mouse), the letter area: Programming Title: Boost :: Iterator_adaptor (ii) Send Station: BBS Shuimu Tsinghua Station (Sun May 19 22:27:09 2002)

Affirmation: Here is just a skill. It seems too much from some kind of vision. So I just introduced the introduction, not to encourage everyone to get to torture your compiler. ;)

II) Simplify complex template parameters list

Many templates, Value, Pointer, Reference, etc. in the ITerator template are not connected between them. In fact, the default values ​​of these template parameters are currently calculated.

template :: value_type, class Reference = typename iterator_defaults :: reference, class Pointer = typename iterator_defaults :: pointer , Class category = typeName std :: item_traits :: item = = typeName std :: iperator_traits :: Difference_Type>

It is reasonable, but have you ever thought if we don't need to provide so many mode-in-case parameters, what will I do? Have you ever thought that if such a result of pushing the result? So last The code we see is sauce purple.

template Struct Iterator_Adaptor

What benefits can such a code? It is our sauce purple instantiation mode.

Iterator_adaptor , item_category_is , value_type_is , reference_is

Notice, the template parameters will not be the same as we declare.;) More wonderful, we can't do this when we use the function default parameters.

Disclaimer: int Foo (int I, long j = 0, double k = 9.8); when called: foo (1, k = 8.7); // Error

However, the template can be instantiated. The reason is that the hand and feet of Iterator_Adaptor started. He used an Iterator_Traits_Gen template. This template does not care about the mean of the template parameters. He is just simply build a Typelist, then use Find_Param typelist from the picking out the desired type .typedef detail :: cons_type :: type, detail :: cons_type :: type, detail :: cons_type :: type, detail :: cons_type :: type, detail :: cons_type :: type, end_of_list>>>>> ArgList;

typedef typename find_param :: type Val; typedef typename find_param :: type Diff; typedef typename find_param :: type Cat; typedef typename find_param :: type PTR; typef typename find_param :: Type Ref;

In combination with the value_type_is similar method appearing in the above code, you must have a problem with Make_ARG. Indeed,

Template struct is_named_parameter {enum {value = false;}};

Template struct is_named_parameter > {enum {value = true};

template struct make_arg {enum {is_named = is_named_parameter :: value}; // we do to make is_named_parameter specialized type of value_type_is, then .... Oh typedef typename if_true <(is_named)> :: template then :: type Make; // other way make_key_valye :: type typedef typename Make :: template select :: type TYPE;

struct make_named_arg {template struct select {typedef typename Value :: type type;};}; // if done with a template parameters struct make_key_value value_type_is {struct make_named_arg {template struct select {typedef typename Value :: type type;};}; // if done with the template parameters struct make_key_value {value_type_is template struct select {typedef detail :: cons_type Type;};}; //

Is it a little experience? So long space, it's not easy to see it. Since I see it here, I will help a busy, write a letter to PEACH, please write Boost :: function. ;)

- AbcdefghijklmnopqrStuvwxyzabcdefghijklmnopqrStuvwxyz

※ Modification: · Huxw at May 19 22:28:23 Modified this article · [From: 166.111.172.6] ※ Source: · BBS Shuimu Tsinghua Station bbs.edu.cn · [from: 166.111.172.6]

转载请注明原文地址:https://www.9cbs.com/read-27786.html

New Post(0)