Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/georgiifirsov/utilites
Currently it is a set of my utility functions and scripts, which I use in my projects and work tasks. You are free to use and modify this stuff for any target you want :)
https://github.com/georgiifirsov/utilites
cpp libraries python utilites
Last synced: 10 days ago
JSON representation
Currently it is a set of my utility functions and scripts, which I use in my projects and work tasks. You are free to use and modify this stuff for any target you want :)
- Host: GitHub
- URL: https://github.com/georgiifirsov/utilites
- Owner: GeorgiiFirsov
- License: mit
- Created: 2019-07-25T07:54:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-18T15:23:35.000Z (almost 5 years ago)
- Last Synced: 2024-08-10T04:23:16.008Z (3 months ago)
- Topics: cpp, libraries, python, utilites
- Language: C++
- Homepage:
- Size: 2.21 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Utilites
This repo contains various utilites for common computer usage and C++ programming. Fell free to use, modify and contribute :)
My target is to build a large base of code with useful stuff.## Table of contents
- Utilites for programming
- [ArrayLength](#ArrayLength)
- [is_convertible and is_convertible_v](#is_convertible-and-is_convertible_v)
- [ThrowsException and ThrowsAnyException](#ThrowsException-and-ThrowsAnyException)
- Utilites for another tasks
- [LookUp](#LookUp)### ArrayLength
`ArrayLength` is a function, that calculates length of C-style static array in compile time. Requires at least C++11.It was created to use with old API in modern C++, in such moments, when you can not replace C-style array with std::vector, std::string or std::array.
Example:
```cpp
int aiFirst[] = { 1, 2, 3, 4, 5};std::cout << ArrayLength(aiFirst); // prints: 5
int aiSecond[ArrayLength(aiFirst)];
assert( ArrayLength(aiFirst) == ArrayLength(aiSecond) );
assert( ArrayLength(aiSecond) == 5 );constexpr auto ulLength = ArrayLength(aiFirst);
assert( ulLength == 5 );
```### is_convertible and is_convertible_v
`is_convertible` is a class, that contains variable value, which is true, when and only when first type is implicitly convertible to second one (same types are allowed). `is_convertible_v` is just a simpler way to use class above.
Example:
```cpp
std::cout << std::boolalpha;std::cout << is_convertible::value; // prints: true
std::cout << is_convertible_v; // prints: true
std::cout << is_convertible_v>; // prints: false
// std::vector(int) is explicit constructor
```### ThrowsException and ThrowsAnyException
These two functions return true, if callable object (parameter) throws an exception. Here better to show an example:
```cpp
void foo() noexcept { }
void bar() { throw std::runtime_error("Error"); }
void baz(int t, std::string str) { if (!t) throw std::logic_error("Error"); }std::cout << std::boolalpha;
std::cout << ThrowsException(foo); // prints: false
std::cout << ThrowsException(bar); // prints: true
std::cout << ThrowsException(bar); // prints: true
std::cout << ThrowsException(bar); // prints: falsestd::cout << ThrowsException(baz, 1, "Text"); // prints: false
std::cout << ThrowsException(baz, 0, "Text"); // prints: truestd::cout << ThrowsAnyException(foo); // prints: false
std::cout << ThrowsAnyException(bar); // prints: true
std::cout << ThrowsAnyException(baz, 1, "Text"); // prints: false
std::cout << ThrowsAnyException(baz, 0, "Text"); // prints: true
```### LookUp
This simple python script can help you to find files with specific line inside. For instance, you need to find all
files with boolean variable bFlag. So you can run following command:
```bash
python LookUp.py dir=my_dir "bool bFlag"
```Full usage of this utilite:
```
python LookUp.py [dir=] [mode=] string1 [string2 [string3 ...]]
Searches strings string1, string2, etc. in all files in specified directory search_dir
Parameters:
- dir - directory with files (by default - directory with script)
- mode - type of search:
0 - search in subdirectories too (default)
1 - search only in current directory
```