Tag: or
C++ Map: Erase by Value or Callback while iterating | erase_if for map
In this article we will discuss two different ways to erase elements from map i.e. In previous article we discussed how to erase elements by key and iterator using member function std::map::erase. But there is no default function to delete elements by value instead of key or delete elements based on callback. Advertisements We will …
C++ Map: Erase by Value or Callback while iterating | erase_if for mapRead More
C++ : How to Sort a List of objects with custom Comparator or lambda function
In this example we will discuss different ways to sort a std::list of user defined data types with custom comparators or lambda functions. Suppose we have a type Player that contains Id and name. Advertisements struct Player { int id; std::string name; Player(int playerId, std::string playerName) : id(playerId), name(playerName) { } bool operator <(const Player …
C++ : How to Sort a List of objects with custom Comparator or lambda functionRead More
C++11 : How to Stop or Terminate a Thread
In this article, we will discuss how to stop or terminate a thread in C++11. C++11 does not provides a direct method to stop a running thread and that’s because that thread might have some resources to release or close before exit i.e. What if a thread has acquired a lock and we kill that …
C++ : How to read or write objects in file | Serializing & Deserializing Objects
In this article we will discuss how to write objects to file and how to read them back from to file and fill in object. Suppose we have a class Student i.e. class Student { public: std::string mName; std::string mId; std::string mPhoneNumber; Student(std::string id = “”, std::string name = “”, std::string phone = “”) : …
C++ : How to read or write objects in file | Serializing & Deserializing ObjectsRead More
C++ : Check if given path is a file or directory using Boost & C++17 FileSystem Library
In this article we will discuss different ways to check if given path is of file or directory that exists using Boost Filesystem Library & C++17 Filesystem Library. Both Boost Filesystem library & C++17 Experimental filesystem library provides certain functions that we are going to use here, Advertisements bool exists(const path& p); In Boost Library’s …
C++ : Check if given path is a file or directory using Boost & C++17 FileSystem LibraryRead More
C++: How to get filename from a path with or without extension | Boost | C++17 FileSytem Library
In this article we will discuss different ways to get filename from a path with or without extension using, Boost Filesystem Library C++17 Filesystem Library Prior to c++11 Days Suppose we have a file path i.e. Advertisements “/home/user/sample/temp/data.csv” We want to fetch file name from this path i.e. “data.csv” and “data” (With or without extension). …
C++ : How to reverse a List or sub-list in place?
In this article we will discuss how to discuss different ways to reverse a complete std::list or a sub list inside a list. Suppose we have a list of strings i.e. Advertisements std::list<std::string> listOfStrs = { “is”, “of”, “the”, “Hi”, “Hello”, “from” }; Now we want to reverse it i.e. from , Hello , Hi …
C++ : How to copy / clone a STL List or Sub List
In this article we will discuss different techniques to clone the whole list or copy just a sub list. Suppose we have a std::list of strings i.e. Advertisements // List of strings std::list<std::string> listOfStrs = { “of”, “is”, “from”, “this”, “at”, “to” }; Now let’s see how to copy this or a sub list from …
Python : How to Check if an item exists in list ? | Search by Value or Condition
In this article we will discuss different ways to check if a given element exists in list or not. Table of Contents Introduction Check if element exists in list using python “in” Operator Check if element exist in list using list.count() function Check if element exist in list based on custom logic Introduction Suppose we …
Python : How to Check if an item exists in list ? | Search by Value or ConditionRead More
Python : Sort a List of numbers in Descending or Ascending Order | list.sort() vs sorted()
In this article we will discuss how to sort a list of numbers in ascending and descending order using two different techniques. list.sort() vs sorted() list’s sort() function In Python, list provides a member function sort() that can sorts the calling list in place. Advertisements sorted() Function It’s a built in function that accepts an …
Python : Sort a List of numbers in Descending or Ascending Order | list.sort() vs sorted()Read More