zoukankan      html  css  js  c++  java
  • C++第六章经验整理2

    There are two list sequence containers are provided by STL namely forward_list and list.

    Forward_list sequence container implements a Singly Linked List.

    Pair container is defined under the header file <utility> therefore one should include header before using pair container.

     If a pair is not initialized then by default both parts of the pair is initialized to zero.

    Any is an STL container provided by C++ to store value or objects of any type.

    There are three basic ways of constructing any variable. They are done using copy initialization, using the constructor or using an assignment operator.

    To initialize an any variable using copy initialization we use the following syntax:

    any variable_name = value;

    To initialize an any variable using assignment operator we use the following syntax:

    any variable_name;
    variable_name = value;

    <any> header file is required to use any container and its realted functions.

    C++ does not allow programmer to directly print the value of any container variable. One need type cast the any variable before printing.

    In this program as we are trying to convert an string into char* which is not same therefore the program gives run-time error saying bad_any_cast.

    bad_any_cast exception is thrown when typecasting is not done properly by the user i.e. if any is storing int value and we are trying to cast it into a string then the program will throw bad_any_cast exception.

    emplace() function is used to change the object contained in any container i.e destroying the present object and creating the new object for the value given by the user.

    reset() function is provided with any to destroy an object contained in any variable in case it is not needed.

    C++ STL-heap container provides sort_heap() function to sort the heap into ascending order which will no longer remain a heap.C++ STL-heap container provides sort_heap() function to sort the heap into ascending order which will no longer remain a heap.

    C++ STL-heap container provides is_heap_until() function which returns the iterator to the position till the container is a heap. For example, we have 7 5 3 1 10 12 so till 1 the sequence forms a heap so this function will return the iterator to the position of element 1.

    vtable is a lookup table that is used to resolve the function calls in dynamic/late binding manners.

     Classes having virtual functions only need vtable because in those cases only we need to resolve function calls in a dynamic manner.

    vptr is a hidden pointer available with classes which are used to point to the virtual table of a class.

    his class has two virtual functions defined. A class having virtual functions by default has a real pointer vptr. Therefore though not mentioned the class has a real pointer ptr which is of size 8 hence the output is 8. The pointer size differs depending on the system, therefore the output may vary in different systems.

    Generators are objects that generates uniformly distributed numbers which help in generating random numbers.

    <random> header file is required for using generators and distributions which helps in generating random numbers in a program.

    Pseudo-random number engines are used to generate random numbers based on an initial seed provided to them.

    There are three types of Pseudo-random number engines based on the algorithm they use. They are linear_congruential_engine, mersenne_twister_engine and subtract_with_carry_engine.

    Random number generator is a random number generator which generates non-deterministic random numbers.

    Engine adaptor is a class template that adapts a pseudo-random number generator to produce random number having a specific number of bits.

    There are three types of Engine adaptors in C++, namely discard_block_engine, independent_bits_engine and shuffle_order_engine.

    is_same() function is used to check whether two variables have the same characteristics or not.

    remove_extent() function removes the first dimension i.e. the first dimension from the given array.

     Object that can hold more than one elements having different types. For example, an object holding int, float and char types.

    get() function is provided with header file to access an element of a tuple.

    tuple_size is used to get the number of elements inside a tuple. For example the tuple_size of tp = {1, 4, “hello”} is 3.

    Valarray is a special container provided by C++ to hold and perform mathematical operations on array efficiently.

    The indexing of bitset variable starts from rightmost bit i.e. if you have b = 1100 as your bitset then b[0] = 0, not 1.

    <bitset> header provides the any() function which returns true if any of the bit is set to 1 in the bitset variable.

    Composition is also a type of Both Aggregation and Association relationship. Composition relationships are string relationships whereas others are a superset of this relationship.

    Composition models the part-of relationship between classes. In this children cannot exits without a parent, therefore, they are part of each other.

    Aggregation models the has-a relationship between classes. In this children can exist without a parent, therefore, they have a relationship.

    As unordered map has no order of keys therefore hash table is used to store key-value pairs in a hash table.

    The map has some order of stored keys therefore red black tree is used to maintain that order and access the elements as soon as possible.

  • 相关阅读:
    vim的一些基本配置
    做菜好吃的小技巧02
    SQLServer创建用户登录
    Python库整理
    centos7开机界面出现多个选项
    Elasticsearch和MongoDB简要对比
    OLTP与OLAP
    CentOS7命令总结
    windows下快速删除命令
    Idea配置热部署
  • 原文地址:https://www.cnblogs.com/hhlys/p/13515085.html
Copyright © 2011-2022 走看看