c++

Key already exists in unordered_map, but “find” returns as not found

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-20 02:19:15
问题 I constructed an unordered_map using key type rot3d, which is defined below: #ifndef EPS6 #define EPS6 1.0e-6 #endif struct rot3d { double agl[3]; // alpha, beta, gamma in ascending order bool operator==(const rot3d &other) const { // printf("== used\n"); return abs(agl[0]-other.agl[0]) <= EPS6 && abs(agl[1]-other.agl[1]) <= EPS6 && abs(agl[2]-other.agl[2]) <= EPS6; } }; Equality of rot3d is defined by the condition that each component is within a small range of the same component from the

Key already exists in unordered_map, but “find” returns as not found

烂漫一生 提交于 2021-02-20 02:18:08
问题 I constructed an unordered_map using key type rot3d, which is defined below: #ifndef EPS6 #define EPS6 1.0e-6 #endif struct rot3d { double agl[3]; // alpha, beta, gamma in ascending order bool operator==(const rot3d &other) const { // printf("== used\n"); return abs(agl[0]-other.agl[0]) <= EPS6 && abs(agl[1]-other.agl[1]) <= EPS6 && abs(agl[2]-other.agl[2]) <= EPS6; } }; Equality of rot3d is defined by the condition that each component is within a small range of the same component from the

ZeroMQ with NORM - address already in use error was thrown on 2nd .bind() - why?

无人久伴 提交于 2021-02-20 02:13:34
问题 I'm using ZeroMQ with NACK-Oriented Reliable Multicast ( NORM ) norm:// protocol. The documentation contains only a Python code, so here is my C++ code: PUB Sender : string sendHost = "norm://2,127.0.0.1:5556";// <NormNodeId>,<addr:port> string tag = "MyTag"; string sentMessage = "HelloWorld"; string fullMessage = tag + sentMessage; zmq::context_t *context = new zmq::context_t( 20 ); zmq::socket_t publisher( *context, ZMQ_PUB ); zmq_connect( publisher, sendHost.c_str() ); zmq_send( publisher,

Using mutable to allow modification of object in unordered_set

怎甘沉沦 提交于 2021-02-20 02:13:33
问题 Please consider the following code: #include <iostream> #include <unordered_set> struct MyStruct { int x, y; double mutable z; MyStruct(int x, int y) : x{ x }, y{ y }, z{ 0.0 } { } }; struct MyStructHash { inline size_t operator()(MyStruct const &s) const { size_t ret = s.x; ret *= 2654435761U; return ret ^ s.y; } }; struct MyStructEqual { inline bool operator()(MyStruct const &s1, MyStruct const &s2) const { return s1.x == s2.x && s1.y == s2.y; } }; int main() { std::unordered_set<MyStruct,

How do I place a group of variables in a specific section in gcc, is there anything like #pragma default_variable_attributes available with arm

廉价感情. 提交于 2021-02-20 02:08:10
问题 The below link https://www.iar.com/support/tech-notes/linker/how-do-i-place-a-group-of-functions-or-variables-in-a-specific-section/ explains how a group of variables can be placed in a specific section, this is with IAR arm linker. Pasting the example (for which i want a gcc equivalent) from the link here /* Place following data in section MY_DATA */ #pragma default_variable_attributes = @ "MY_DATA" int data1; int data2; /* Stop placing data in section MY_DATA */ #pragma default_variable

Redirecting stdout in win32 does not redirect stdout

拜拜、爱过 提交于 2021-02-20 01:54:39
问题 I'm trying to redirect stdout so that printf in a windows application will go to a file of my choice. I'm doing this: outFile = fopen("log.txt", "w"); *stdout = *outFile; setvbuf(stdout, NULL, _IONBF, 0); but printf still writes to the console (or nowhere on a GUI based win32 application) I can redirect 'std::cout' by doing this: outFileStr = std::ofstream(outFile); std::cout.rdbuf(outFileStr.rdbuf()); But printf seems to be doing its own thing. Unfortunately, I need to redirect printf as I'm

colon in for loop in C++

岁酱吖の 提交于 2021-02-20 01:01:23
问题 In the following code I am trying to edit the contents of an unordered_map: class A { public: A() {std::cout << "Constructor called, address=" << this << std::endl;val=1;} int val; }; void main(void) { std::unordered_map<int,A> um; for (int i=0;i<3;i++) std::cout << "um[" << i << "]=" << &(um[i]) << ", val=" << um[i].val << std::endl; for (auto it : um) std::cout << "&it.second=" << &(it.second) << ", val=" << it.second.val << std::endl; int index = 1; for (auto um_it : um) um_it.second.val =

Why is my data in the frequency domain “mirrored” when performing (2d) IDFT into DFT using FFTW?

狂风中的少年 提交于 2021-02-20 00:49:55
问题 I am manually initializing a state in the 2d frequency domain by setting the real components of certain modes in a 16x16 data set. I then perform a 2d IDFT to acquire the real domain data. This all works as expected. I then perform a DFT on the real domain data to get back (what should be) identical frequency modes to those that I manually initialized. However, they come back with their amplitudes halfed, and their vertical frequencies "mirrored". To illustrate: Input modes: k[1, 0]: 32 + 0i

Using OpenH264 DLL in C# Project

非 Y 不嫁゛ 提交于 2021-02-20 00:42:40
问题 I'm receiving an H264 stream over UDP. I'd like to decode the stream so I can send frames to OpenCV or whatever. I came across Cisco's open sourced H264 decoder here: https://github.com/cisco/openh264 With a little effort I got the decoder solution to build in Visual Studio 2019 and tested it from the command line with a file I created from the raw UDP datagrams. It works. Now I want to figure out how to use the decoder DLL (welsdec.dll) in a C# project. The last time I did anything serious

Using OpenH264 DLL in C# Project

不羁岁月 提交于 2021-02-20 00:42:12
问题 I'm receiving an H264 stream over UDP. I'd like to decode the stream so I can send frames to OpenCV or whatever. I came across Cisco's open sourced H264 decoder here: https://github.com/cisco/openh264 With a little effort I got the decoder solution to build in Visual Studio 2019 and tested it from the command line with a file I created from the raw UDP datagrams. It works. Now I want to figure out how to use the decoder DLL (welsdec.dll) in a C# project. The last time I did anything serious