voronindim / OOP

1 stars 0 forks source link

Замечания по ExpandTemplate #5

Open alexey-malov opened 4 years ago

alexey-malov commented 4 years ago
1>C:\teaching\oop-labs\voronin\OOP\lab_2\ExpandTemplate\ExpandTemplate.cpp(105,50): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>C:\teaching\oop-labs\voronin\OOP\lab_2\ExpandTemplate\ExpandTemplate.cpp(149,44): warning C4267: '+=': conversion from 'size_t' to 'int', possible loss of data

Если хотите хранить знаковый тип, размер которого совпадает с size_t - используйте ptrdiff_t

alexey-malov commented 4 years ago
>ExpandTemplate.exe input.txt output.txt мир хлеб
alexey-malov commented 4 years ago
alexey-malov commented 4 years ago

https://github.com/voronindim/OOP/blob/2fc9235f2775243c9241b8f59ebf17af569ef05c/lab_2/ExpandTemplate/ExpandTemplate.cpp#L81-L96

alexey-malov commented 4 years ago

https://github.com/voronindim/OOP/blob/2fc9235f2775243c9241b8f59ebf17af569ef05c/lab_2/ExpandTemplate/ExpandTemplate.cpp#L133-L154

Можно воспользоваться structure bindings (фича из C++17) для разбиения пары отдельные фрагменты:

    string resultStr;
    int pos = 0;
    for (auto& [startSubstring, stringToReplace] : substrings)

https://github.com/voronindim/OOP/blob/2fc9235f2775243c9241b8f59ebf17af569ef05c/lab_2/ExpandTemplate/ExpandTemplate.cpp#L148

alexey-malov commented 4 years ago

https://github.com/voronindim/OOP/blob/2fc9235f2775243c9241b8f59ebf17af569ef05c/lab_2/ExpandTemplate/ExpandTemplate.cpp#L98-L108

alexey-malov commented 4 years ago
alexey-malov commented 4 years ago