/cxx-tasks

C++ training tasks

Primary LanguageC++

About

This project is intended to test students skills in C++ language.

Tasks list

  1. I/O stream manipulators.
  2. Iterator.
  3. Proxy object.
  4. Using of std::variant.
  5. Parsers by boost::spirit::x3:
    • csv;
    • json.
  6. Type map to describe mapping of compile-time types to runtime values.

How to build?

Just use cmake:

$ mkdir build
$ cd build
build/ $ cmake ..
build/ $ make -j
build/ $ ctest

If you want to work with particular project:

build/ $ cmake ../iterator
build/ $ make -j
build/ $ ctest

Another approach is to use docker image igsha/cxx-miet.

  1. Install docker.

  2. Pull image and start docker-session:

    $ docker run -u `id -u`:`id -g` -v $PWD:/data -it igsha/cxx-miet:0.1
    bash-4.4$ <-- this means you are in docker-session
    
    • once downloaded session will be available locally;
    • flag -u `id -u`:`id -g` is used to bring the same permissions into docker as your local user permissions;
    • flag -v $PWD:/data is used to mount your current source directory into docker like folder /data;
    • notes for Windows users: you don't need flag -u, replace $PWD with the name of current directory.
  3. Inside docker-session call the same command sequence like was done above (mkdir, cd, cmake, etc.).

  4. To exit docker-session press Ctrl-D or type exit command.

How to work with projects

Each project is a complete cmake-project with

  • CMakeLists.txt;
  • include that represent "source" of a project;
  • tests - is a main part to check task.

Students should work only with files inside include folder. The main criteria is to pass all tests of a project.

How to answer in-source questions

There are some questions in the source of projects that have the form of C-comments //?. Print the answer just below a question using the form of C-comment //!.

Use these questions as a hint to a task.

Additional questions

  1. How to declare and define function within another function?

  2. How to copy lambda?

  3. How to call non-constant method of a member within constant method?

    struct cba
    {
        std::ostream& o;
    }
    
    struct abc
    {
        void mark() const
        {
            obj.o << 123;
        }
    
        ?cba? obj;
    }
    
  4. How to initialize members of the same class in different constructors?

  5. How to initialize a member in separate function within member initializer list?

[optional] Write complete project (CMakeLists.txt, folder hierarchy and tests). Themes:

  • INI-parser with EBNF in comments;
  • implement iterator of multidimensional array with the ability to choose the direction of iterations (by x-, y- or z-axis, etc.);
  • provide example to work with google-protobuf.