diff --git a/playground/cpp/main.cpp b/playground/cpp/main.cpp new file mode 100644 index 0000000..fe9dcf1 --- /dev/null +++ b/playground/cpp/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +int main() +{ + // Create an unordered_map of three strings (that map to strings) + std::unordered_map u = + { + {"RED", "#FF0000"}, + {"GREEN", "#00FF00"}, + {"BLUE", "#0000FF"} + }; + + // Helper lambda function to print key-value pairs + auto print_key_value = [](const auto& key, const auto& value) + { + std::cout << "Key:[" << key << "] Value:[" << value << "]\n"; + }; + std::cout << "Iterate and print key-value pairs of unordered_map, being\n" + "explicit with their types:\n"; + for (const std::pair& n : u) + print_key_value(n.first, n.second); + std::cout << "\nIterate and print key-value pairs using C++17 structured binding:\n"; + for (const auto& [key, value] : u) + print_key_value(key, value); + + // Add two new entries to the unordered_map + u["BLACK"] = "#000000"; + u["WHITE"] = "#FFFFFF"; + + std::cout << "\nOutput values by key:\n" + "The HEX of color RED is:[" << u["RED"] << "]\n" + "The HEX of color BLACK is:[" << u["BLACK"] << "]\n\n"; + + std::cout << "Use operator[] with non-existent key to insert a new key-value pair:\n"; + print_key_value("new_key", u["new_key"]); + + std::cout << "\nIterate and print key-value pairs, using `auto`;\n" + "new_key is now one of the keys in the map:\n"; + for (const auto& n : u) + print_key_value(n.first, n.second); +} diff --git a/playground/init.lua b/playground/init.lua index 61ec199..6c50839 100644 --- a/playground/init.lua +++ b/playground/init.lua @@ -77,6 +77,36 @@ local function load_plugins() }) end, }, + { + 'hrsh7th/nvim-cmp', + dependencies = { + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + }, + config = function () + -- Add additional capabilities supported by nvim-cmp + local cmp = require 'cmp' + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + },}), + sources = { + { name = 'nvim_lsp' }, + }, + } + end, + }, { 'ray-x/go.nvim', dev = (plugin_folder() ~= ''),