Daily Archives: December 8, 2020

C++ || How To Get A List Of Files At A Given Path Directory Using C++

The following is a module with functions which demonstrates how to get a list of files at a given directory path using C++.

The function demonstrated on this page returns a list of std::filesystem::directory_entry, which contains information about the files in the given directory.


1. Get Files In Directory

The example below demonstrates the use of ‘Utils::getFilesInDirectory‘ to get a list of files at a given path directory.

The optional function parameter lets you specify the search option. Set the search option to True to limit the search to just the current directory. Set the search option to False to expand the search to the current directory and all subdirectories when searching for files.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C++ || How To Make Map & Unordered Map Keys Case Insensitive Using C++

The following is a module with functions which demonstrates how to make map and unordered_map keys case insensitive using C++.


1. Case Insensitive – Map

The example below demonstrates how to make a map with a string key case insensitive.

To do this, the comparison function needs to be overridden.


2. Case Insensitive – Unordered Map

The example below demonstrates how to make an unordered map with a string key case insensitive.

To do this, the comparison and the hash function needs to be overridden.


3. Full Examples

Below is a full example demonstrating the concepts on this page.

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C++ || How To Search For & Find A Specific Element In A Vector Using C++

The following is a module with functions which demonstrates how to search for and find a specific element in a vector using C++.

The function demonstrated on this page is a template, so it should work on vectors of any type. It also uses a predicate to determine the item to select.


1. Find

The example below demonstrates the use of ‘Utils::find‘ to find the first element in a sequence of values based on a predicate.

The predicate determines the item to find.


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

C++ || How To Filter & Select Items In An Array/Vector/Container & Get The Results Using C++

The following is a module with functions which demonstrates how to filter and select items in an array/vector/container, and get the results using C++.

The function demonstrated on this page is a template, so it should work on containers of any type. It also uses a predicate to determine the items to select.


1. Filter – Integer Array

The example below demonstrates the use of ‘Utils::filter‘ to filter an integer array based on a predicate and return its results.

The predicate determines the items to filter and select.


2. Filter – String Vector

The example below demonstrates the use of ‘Utils::filter‘ to filter a sequence of values based on a predicate and return its results.

The predicate determines the items to filter and select.


3. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


4. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.