Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
New C++ Insights Episode
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <map> #include <string> #include <iostream> #include <vector> #include <cstdint> class ConfigManager { private: std::map<std::string, std::vector<uint8_t>> configs; static const std::vector<uint8_t>& getDefaultConfig() { static std::vector<uint8_t> def {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; return def; } public: ConfigManager() { configs["database"] = { 'h','o','s','t','=','l','o','c','a','l','h','o','s','t',';', 'p','o','r','t','=','5','4','3','2' }; } const std::vector<uint8_t>& findConfig(const std::string& name) const { auto it = configs.find(name); if (it != configs.end()) return it->second; return getDefaultConfig(); } }; int main() { ConfigManager configManager; const std::vector<uint8_t>& dbConfig = configManager.findConfig("database"); std::cout << "Database config: "; for (uint8_t byte : dbConfig) { std::cout << static_cast<char>(byte); } }
Insight:
Console: