c++

Getting GCC/Clang to use CMOV

本小妞迷上赌 提交于 2021-02-19 04:38:05
问题 I have a simple tagged union of values. The values can either be int64_ts or doubles . I am performing addition on the these unions with the caveat that if both arguments represent int64_t values then the result should also have an int64_t value. Here is the code: #include<stdint.h> union Value { int64_t a; double b; }; enum Type { DOUBLE, LONG }; // Value + type. struct TaggedValue { Type type; Value value; }; void add(const TaggedValue& arg1, const TaggedValue& arg2, TaggedValue* out) {

Cmake: linking to static internal library without exporting it

强颜欢笑 提交于 2021-02-19 04:36:12
问题 I have a project with this structure: /path/to/my/project ├── CMakeLists.txt ├── internal-libs │ ├── internal-lib1 ├── libs │ ├── lib1 │ ├── lib2 lib1 is a static library. lib2 is a static library. internal-lib1 is a static library. lib2 links statically to lib2 and internal-lib1. lib1 and lib2 are going to be exported but internal-lib1 will be left behind. For the linkage, I have: target_link_libraries(lib2 PRIVATE internal-lib1) target_link_libraries(lib2 PRIVATE lib1) My understanding is

When is integer to floating point conversion lossless?

╄→гoц情女王★ 提交于 2021-02-19 04:35:27
问题 Particularly I'm interested if int32_t is always losslessly converted to double . Does the following code always return true ? int is_lossless(int32_t i) { double d = i; int32_t i2 = d; return (i2 == i); } What is for int64_t ? 回答1: Question: Does the following code always return true? Always is a big statement and therefore the answer is no . The C++ Standard makes no mention whether or not the floating-point types which are known to C++ ( float , double and long double ) are of the IEEE-754

convert an std::string to a Swift String

天大地大妈咪最大 提交于 2021-02-19 04:24:26
问题 Short version: how can I convert an std::string (object returned by a .cpp function called from a .Swift file using bridging) to a Swift String ? Long version: I have a library written in C++ and I have to call some code using Swift. I created a bridge, adding two files in my Xcode projects: a bridging header, which allows Swift to call C functions (afaik Swift can't call C++ functions directly, so it needs to pass through C functions) //file bridgingHeader.h const char * getLastOpenedFile();

How to parse a grammar into a `std::set` using `boost::spirit`?

耗尽温柔 提交于 2021-02-19 04:20:20
问题 TL;DR How to parse the result of a boost::spirit grammar into an std::set ? Full problem statement As an exercise to learn how to use boost::spirit , I am designing a parser for X.500/LDAP Distinguished Names. The grammar can be found in a BNF format in the RFC-1779. I "unrolled" it and translated it into boost::spirit rules. That's the first step. Basically, a DN is a set of RDN (Relative Distinguished Names) which themselves are tuples of (Key,Value) pairs. I think about using typedef std:

How to parse a grammar into a `std::set` using `boost::spirit`?

陌路散爱 提交于 2021-02-19 04:18:06
问题 TL;DR How to parse the result of a boost::spirit grammar into an std::set ? Full problem statement As an exercise to learn how to use boost::spirit , I am designing a parser for X.500/LDAP Distinguished Names. The grammar can be found in a BNF format in the RFC-1779. I "unrolled" it and translated it into boost::spirit rules. That's the first step. Basically, a DN is a set of RDN (Relative Distinguished Names) which themselves are tuples of (Key,Value) pairs. I think about using typedef std:

Read cells from Excel in C++?

徘徊边缘 提交于 2021-02-19 04:09:58
问题 I was wondering how you can read specific cells from an Excel spreadsheet, in C++. I understand we have to use the "fstream" library, but I don't know exactly how I could get those values from a certain cell, and print it on the screen. Any help would be appreciated, thanks! Carpetfizz 回答1: in linux you have this free: http://libxls.sourceforge.net/ in windows you have http://www.libxl.com/ which seems to cost money: Book* book = xlCreateBook(); if(book) { if(book->load(L"example.xls")) {

Eliminating instantiation of useless destructor calls?

浪尽此生 提交于 2021-02-19 04:08:35
问题 Well, my colleague is pretty in depth nitpicking about eliminating unnecessarily code instantiations for destructor functions. Still same situation, as mentioned in this question: Very limited space for .text section (less 256 KB) Code base should scale among several targets, including the most limited ones Well known use cases of the code base by means some destructor logic is neccesary to manage object lifetimes or not (for many cases life-time of objects is infinite, unless the hardware is

Read cells from Excel in C++?

烂漫一生 提交于 2021-02-19 04:08:11
问题 I was wondering how you can read specific cells from an Excel spreadsheet, in C++. I understand we have to use the "fstream" library, but I don't know exactly how I could get those values from a certain cell, and print it on the screen. Any help would be appreciated, thanks! Carpetfizz 回答1: in linux you have this free: http://libxls.sourceforge.net/ in windows you have http://www.libxl.com/ which seems to cost money: Book* book = xlCreateBook(); if(book) { if(book->load(L"example.xls")) {

gcc doesn't accept out-of-line definition of member with non-type template parameter defined via nested templated using clause

戏子无情 提交于 2021-02-19 04:07:51
问题 The title seems convoluted but our test-case is actually a minimal example for a real case. We have code for which we want to choose implementation of a method based on the template parameter. We during clean up we defined conditional enable_if_t with using clause, and as next step wanted to put definition out of line, this produced following code: #include <type_traits> #include <iostream> #include <string> template <typename T> struct A { template <typename U> using is_int_or_float = std: