Should i free memory when i am using boost::posix_time::time_facet

Advertisements I have a method that returns the expiration date of a subscription and uses boost::posix_time::time_facet to convert Unix time format to string. In tutorials I’ve seen, time_facet is created using the "new" keyword, but I haven’t seen any examples using "delete" (like in this thread). Should I free memory after using time_facet or does… Read More Should i free memory when i am using boost::posix_time::time_facet

template argument deduction compile error with boost's `static_vector`

Advertisements The following piece of code works fine: #include <span> #include <boost/container/static_vector.hpp> #include <iostream> #include <vector> int main(){ boost::container::static_vector<int, 10> x{1,2,3}; std::vector y{1,2,3}; for(const auto& i : std::span(y.begin()+1, y.end())) std::cout << i << ‘\n’; } but will fail at compile if i try to use x in place of y in the ranged for loop:… Read More template argument deduction compile error with boost's `static_vector`

why can't use ternary operator with different types when boost variable can hold multiple types?

Advertisements I have something like below, but unable to compile it. I don’t get it why I can’t have different type when my variable can hold different types? My code: #include <boost/variant.hpp> #include <iostream> typedef boost::variant<int, float, double, std::string> MultiType; int main() { int a = 1; std::string b = "b"; bool c = true;… Read More why can't use ternary operator with different types when boost variable can hold multiple types?

Area of Boost c++ in Square Meters

Advertisements I have a boost::geometry::model::polygon<Point> Algorithm::poly and i’m looking for the area of the polygon with area = bg::area(poly); the result is 1.10434e+08 When i’m reading the documentation, i can see "The units are the square of the units used for the points defining the surface". I really don’t understand what it means. https://www.boost.org/doc/libs/1_65_0/libs/geometry/doc/html/geometry/reference/algorithms/area/area_1.html I… Read More Area of Boost c++ in Square Meters

Elasticsearch – how do i add `boost` to `constant_score` in bodybuilder?

Advertisements I have the following bodybuilder query :- bodybuilder() .orQuery(‘match_all’, {}) .orQuery(‘constant_score’, null , (qr) => { return qr.filter(‘range’, ‘stock_sum’, {gte: 1}) }) .build() Which basically generate the following (Query simulator HERE) { "query": { "bool": { "should": [ { "match_all": {} }, { "constant_score": { "filter": { "range": { "stock_sum": { "gte": 1 }… Read More Elasticsearch – how do i add `boost` to `constant_score` in bodybuilder?

Boostrap5 autofit column width

Advertisements Having the following code (pen here) I tried to autofit the second column width to it content with auto margins that does not seem to work. .col { border: 1px solid red; } .autofit { margin: auto; width: auto; max-width: auto; } <link href=”https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css&#8221; rel=”stylesheet”/> <div class=”row m-5″> <div class=”col”>1</div> <div class=”col autofit”>2*</div> <div… Read More Boostrap5 autofit column width

Is there a simpler way to write a concept that accepts a set of types?

Advertisements Essentially, is there a shorter/cleaner way to define Alphabet than using a bunch of std::same_as/std::is_same? struct A {}; struct B {}; struct C {}; … template <typename T> concept Alphabet = std::same_as<T, A> || std::same_as<T, B> || std::same_as<T, C> || … You could accomplish this (sort of) by defining a base class and using… Read More Is there a simpler way to write a concept that accepts a set of types?

No match for ‘boost::shared_ptr::operator=’

Advertisements This is the code I have that causes the error below: class CAlternateMerchantList { public: CAlternateMerchant::SP m_pAlternateMerchantList[MAX_PLAYER_LIST]; int m_nMax; int m_nCur; CAlternateMerchantList() { int i; for (i = 0; i < MAX_PLAYER_LIST; i++) m_pAlternateMerchantList[i] = NULL; m_nMax = 0; m_nCur = 0; } The error I get is the following: PersonalShop.h: In constructor ‘CAlternateMerchantList::CAlternateMerchantList()’:… Read More No match for ‘boost::shared_ptr::operator=’

Taking the address of a boost::any variable

Advertisements Consider: #include <boost/any.hpp> #include <iostream> #include <vector> #include <string> int main() { //Code snippet 1 boost::any variable(std::string("Hello ")); std::string* string_ptr_any = boost::any_cast<std::string>(&variable); std::cout << "Pointer value is " << string_ptr_any <<", variable’s address is " << &variable << std::endl; //End Code snippet 1 //Code snippet 2 std::string normalstring = "hello_normal"; std::string* normalstringptr = &normalstring;… Read More Taking the address of a boost::any variable

How to wrap iterator of boost::circular_buffer?

Advertisements I’m trying to use boost::circular_buffer to manage fixed size of the queue. To do that, I wrap boost::circular_buffer by using class Something. class Something { public: Something(); private: boost::circular_buffer<int> buffer; }; Here, the problem is that class Something should wrap iterator of buffer. For example, If I use std::vector<int>, it is simple: class Something… Read More How to wrap iterator of boost::circular_buffer?