error: no match for operator= in map c++ - c++

im trying to import data from an XML file and save them in a 5D map
// declaration of the map
map<char *, map<char *, map<char*, map<char *, map<char*, map<char*, char*, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str>, cmp_str> XmlData;
im using for the XML-Parsing the RapidXML Parser
file<> xmlFile("jobs.xml");
xml_document<> doc;
doc.parse<0>(xmlFile.data());
xml_node<> *node = doc.first_node();
while(node != 0) {
xml_node<> *child = node->first_node();
while (child != 0)
{
xml_node<> *subchild = child->first_node();
while (subchild != 0)
{
xml_node<> *subsubchild = subchild->first_node();
while (subsubchild != 0)
{
xml_node<> *subsubsubchild = subchild->first_node();
while (subsubsubchild != 0)
{
// the error appears here
XmlData[node->name()][child->name()][subchild->name()][subsubchild->name()][subsubsubchild->name()] = subsubsubchild->value();
subsubsubchild = subsubsubchild->next_sibling();
}
subsubchild = subsubchild->next_sibling();
}
subchild = subchild->next_sibling();
}
child = child->next_sibling();
}
node = node->next_sibling();
}
I had to use 5 while loops to iterate all nodes
XML :
<Job>
<UserJob>
<RuleSet>
<def>
<Path>detection_c_new.dcp</Path>
<WkspName>MyWS</WkspName>
<UserName>Admin</UserName>
</def>
</RuleSet>
</UserJob>
<Scenes>
<Scene1>
<Info>
<def>
<ID>0</ID>
<Name>Scene 1</Name>
</def>
</Info>
<Layers>
<Layer1>
<Index>0</Index>
<Name>Layer 1</Name>
<ImgPath>CTX_MEM_Detail.jpg</ImgPath>
</Layer1>
</Layers>
<ExpItems>
<ExpItem1>
<Name>MyStats1</Name>
<Driver>CSV</Driver>
<Type>1</Type>
<Path>CTX_MEM_Detail.csv</Path>
</ExpItem1>
</ExpItems>
</Scene1>
</Scenes>
</Job>
When compiling using g++ with c++0x under CentOS 6 i get this following error:
Job.cpp:133: error: no match for âoperator=â in â((std::map<char*, std::map<char*, char*, cmp_str, std::allocator<std::pair<char* const, char*> > >, cmp_str, std::all$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:251: note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:266: note: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:286: note: std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compa$

char* is an awful thing to have as map key, and probably value too.
You might use const char* as key is absolutely sure that you pass pointers to stable things, like literal only.
The baseline soulution would use string as both key and payload, and I guess your problem would go away too. The most probable immediate cause is that your value refuses to convert to char*.

Related

How to change a container elements in another 'temporary' container

I have a temporary list that needs to change its elements and erase() them from the list as a way of marking them as done.
std::list<Vertex> temp {vertices.begin(), vertices.end()};
I've tried using Vertex& and Vertex* without success, and the second one makes the code very messy.
What is the proper way to do this? Thanks in advance
Edit: surrounding code
int label = 1;
// change elements without affecting temporary list
std::list<Vertex*> unlabeledVertices {graph.vertices.begin(), graph.vertices.end()};
for (auto iter = unlabeledVertices.begin(); iter != unlabeledVertices.end(); ++label) {
(*iter)->label = label;
// temporary list
std::list<Vertex*> currentLabelVertices;
currentLabelVertices.push_back(*iter);
// check if we can label any other vertex with the current color
auto nestedIter = iter;
for (nestedIter++; nestedIter != unlabeledVertices.end(); ) {
// checking current vertex against any other colored vertex
if (std::none_of(currentLabelVertices.begin(), currentLabelVertices.end(),
[=](const Vertex* v){ return (*nestedIter)->isConnected(*v); })) {
(*nestedIter)->label = label;
currentLabelVertices.push_back(*nestedIter);
nestedIter = unlabeledVertices.erase(nestedIter);
}
else {
nestedIter++;
}
}
iter = unlabeledVertices.erase(iter);
}
Error message:
/usr/bin/g++ -fdiagnostics-color=always -g /home/etzl/projects/c-cpp/test/*.cc -o exec
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
from /usr/include/c++/10/bits/allocator.h:46,
from /usr/include/c++/10/string:41,
from /usr/include/c++/10/bits/locale_classes.h:40,
from /usr/include/c++/10/bits/ios_base.h:41,
from /usr/include/c++/10/ios:42,
from /usr/include/c++/10/ostream:38,
from /usr/include/c++/10/iostream:39,
from /home/etzl/projects/c-cpp/test/main.cc:1:
/usr/include/c++/10/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Vertex*; _Args = {Vertex&}; _Tp = std::_List_node<Vertex*>]’:
/usr/include/c++/10/bits/alloc_traits.h:512:17: required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Vertex*; _Args = {Vertex&}; _Tp = std::_List_node<Vertex*>; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<std::_List_node<Vertex*> >]’
/usr/include/c++/10/bits/stl_list.h:637:33: required from ‘std::__cxx11::list<_Tp, _Alloc>::_Node* std::__cxx11::list<_Tp, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {Vertex&}; _Tp = Vertex*; _Alloc = std::allocator<Vertex*>; std::__cxx11::list<_Tp, _Alloc>::_Node = std::__cxx11::list<Vertex*>::_Node]’
/usr/include/c++/10/bits/stl_list.h:1911:32: required from ‘void std::__cxx11::list<_Tp, _Alloc>::_M_insert(std::__cxx11::list<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {Vertex&}; _Tp = Vertex*; _Alloc = std::allocator<Vertex*>; std::__cxx11::list<_Tp, _Alloc>::iterator = std::__cxx11::list<Vertex*>::iterator]’
/usr/include/c++/10/bits/stl_list.h:1227:19: required from ‘void std::__cxx11::list<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {Vertex&}; _Tp = Vertex*; _Alloc = std::allocator<Vertex*>]’
/usr/include/c++/10/bits/stl_list.h:1840:18: required from ‘void std::__cxx11::list<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, std::__false_type) [with _InputIterator = std::_List_iterator<Vertex>; _Tp = Vertex*; _Alloc = std::allocator<Vertex*>]’
/usr/include/c++/10/bits/stl_list.h:806:26: required from ‘std::__cxx11::list<_Tp, _Alloc>::list(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = std::_List_iterator<Vertex>; <template-parameter-2-2> = void; _Tp = Vertex*; _Alloc = std::allocator<Vertex*>; std::__cxx11::list<_Tp, _Alloc>::allocator_type = std::allocator<Vertex*>]’
/home/etzl/projects/c-cpp/test/main.cc:58:87: required from here
/usr/include/c++/10/ext/new_allocator.h:150:4: error: cannot convert ‘Vertex’ to ‘Vertex*’ in initialization
150 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build finished with error(s)
You should use std::unordered_set<Vertex*> currentLabelVertices instead of a list. It gives O(1) lookup instead of the O(n) solution you have with std::none_of().
Your other problem is here:
std::list<Vertex*> unlabeledVertices {graph.vertices.begin(), graph.vertices.end()};
It doesn't compile because graph.vertices contains Vertex instances, not pointers. The fix is simple:
std::list<Vertex*> unlabeledVertices;
for (auto& vertex : graph.vertices)
unlabeledVertices.push_back(&vertex);

Error to implementation of strategy pattern in C++

I'm trying to implement the design pattern strategy in C++.
The goal for me is to do an operation on 2 numbers.
Here is my context class
operation::operation(std::unique_ptr<calculatorTask> pTask = nullptr)
{
pCalculatorTask = std::move(pTask);
}
operation::~operation();
{
}
void operation::setTask(std::unique_ptr<calculatorTask> pTask)
{
this->pCalculatorTask = std::move(pTask);
}
void operation::executeTask(numberMsg& sValues)
{
pCalculatorTask->calculate(values);
}
This is my implementation :
int main()
{
std::vector<std::unique_ptr<calculatorTask>> myOperation;
myOperation.push_back(std::move(std::unique_ptr<additionTask>(new additionTask())));
myOperation.push_back(std::move(std::unique_ptr<substractionTask>(new substractionTask())));
for (const auto &Ope : myOperation)
{
pOpe->setTask(Ope);
[...]
}
}
I have this error :
error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = calculatorTask; _Dp = std::default_delete]’
pOpe->setTask(Ope);
I don't understand error and how to fix it.

Union of two class vectors in C++

My problem is the following:
I have two vectors of an specific class called "estado" (state):
class estado {
vector <int> prev_estados;
int g; //coste camino
int h; //heuristica
int f; //total
bus autobus;
vector<estado> estados_anteriores;
int n_estudiantes; //numero de lo de abajo
vector<vector<estudiante>> estudiantes; //lista de todos los estudiantes que faltan por subirse al autobus. En el momento que un alumno se sube al autobus, se le elimina
//la lista de estudiantes tiene la forma de [parada_de_origen][simplemente el orden en que se metieron]
Contructor of estado:
estado(vector<int> prev_esta, int G, vector<estado> estados_ant, int n_estudiantess,
vector<vector<estudiante>> estudiantess, int parada_destino, bus autobus) : autobus(autobus) {
prev_estados = prev_esta;
g = G;
h = n_estudiantess*4;
f = g+h;
estados_anteriores = estados_ant;
n_estudiantes = n_estudiantess; //numero que quedan por dejar
estudiantes = estudiantess;
}
And I want to merge them in a single ordered vector using a pre defined function:
bool comparator(estado a, estado b){
if(a.getNEstudiantes()==b.getNEstudiantes()){
if(a.getBus().get_NCarga()==b.getBus().get_NCarga()){
//Aqui se puede implementar homogeneidad de alumnos en el bus
if(a.getG()==b.getG()){
return true;
}else{
//Por una cosa que dijo en clase seria mejor poner que se priorice la G mas grande
return a.getG() > b.getG();
}
}else{
//Cuantos mas niños haya en el bus mejor
return a.getBus().get_NCarga() > b.getBus().get_NCarga();
}
}else{
//Cuantos menos estudiantes queden por entregar mejor
return a.getNEstudiantes() < b.getNEstudiantes();
}
}
Doing some research I came out with the function "set_union", which must be used this way:
vector<estado> v(10);
vector<estado>:: iterator it;
it= set_union(big.begin(),big.end(),small.begin(),small.end(),v.begin(),comparator); //unirse ordenadamene en v
big[a]=v;
In fact I receive the following building error:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_tempbuf.h:60:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_algo.h:62,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/algorithm:62,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/regex:38,
from /cygdrive/c/Users/dasan/CLionProjects/Heuristica_2_2/bus.h:10,
from /cygdrive/c/Users/dasan/CLionProjects/Heuristica_2_2/heuristic.h:5,
from /cygdrive/c/Users/dasan/CLionProjects/Heuristica_2_2/heuristic.cpp:5:
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_construct.h: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = estado; _Args = {}]':
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_uninitialized.h:527:18: required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = estado*; _Size = long unsigned int; bool _TrivialValueType = false]'
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_uninitialized.h:583:20: required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = estado*; _Size = long unsigned int]'
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_uninitialized.h:645:44: required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = estado*; _Size = long unsigned int; _Tp = estado]'
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_vector.h:1352:36: required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = estado; _Alloc = std::allocator<estado>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_vector.h:285:30: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = estado; _Alloc = std::allocator<estado>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<estado>]'
/cygdrive/c/Users/dasan/CLionProjects/Heuristica_2_2/heuristic.cpp:83:63: required from here
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/stl_construct.h:75:7: error: no matching function for call to 'estado::estado()'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
With my basic understancing of c++ I think that the error is in the line
vector<estado> v(10);
With the "(10)" part. In fact if I dont include that, the vector will have no room for store the things inserted and I will receive a Segmentation Error.
What I should do? I appreciate all your help.
EDIT: As #txtechhelp point out, the issue was that my class "estado" doesnt have a default controcutor.
Thanks for the help.

Lambda Works on Latest Visual Studio, but Doesn't Work Elsewhere

So I've written a nasty lambda to satisfy a "shortest amount of code necessary to achieve this" question:
values.resize(distance(
begin(values),
remove_if(begin(values), end(values),
[i = 0U, it = cbegin(intervals), end = cend(intervals)](const auto&) mutable {
return it != end && ++i > it->first && (i <= it->second || (++it, true));
})
));
My problem is that on Visual Studio Community 2015 Update 3 version 14.0.25425.01 this outputs the desired:
4.2 9.1 2.3 0.6 6.4 3.6 1.4 7.5
But on all the other compilers I've tried I get:
4.2 2.3 0.6 1.2 0.3 1.4 2.5 7.5
Can anyone tell me what's causing the different behavior?
You are relying on the fact that the exact closure you pass into the algorithm is the one used as the predicate, but the standard allows it to be copied:
[algorithms.general]/10 (N4140): [Note: Unless otherwise specified, algorithms that take function objects as arguments are permitted to copy
those function objects freely. Programmers for whom object identity is important should consider using a
wrapper class that points to a noncopied implementation object such as reference_wrapper (20.9.3),
or some equivalent solution. —end note ]
This is exactly what libstdc++ does. From v6.2.1:
template<typename _ForwardIterator, typename _Predicate>
_ForwardIterator
__remove_if(_ForwardIterator __first, _ForwardIterator __last,
_Predicate __pred)
{
__first = std::__find_if(__first, __last, __pred);
if (__first == __last)
return __first;
_ForwardIterator __result = __first;
++__first;
for (; __first != __last; ++__first)
if (!__pred(__first))
{
*__result = _GLIBCXX_MOVE(*__first);
++__result;
}
return __result;
}
That call to std::__find_if at the start of the function copies __pred, which means that the value of i is incremented a bit within std::__find_if, but this doesn't change what's going on at the call site.
To fix this problem, you could use std::ref:
auto clos = [i = 0U, it = cbegin(intervals), end = cend(intervals)](const auto&) mutable {
return it != end && ++i > it->first && (i <= it->second || (++it, true));
};
values.resize(distance(begin(values), std::remove_if(begin(values), end(values), std::ref(clos))));
Live demo

Call to non-constexpr function 'std::map...'

I'm attempting to create a pseudo-media center thing on an Arduino and a breadboard, not all that complicated but this is my first project with C++ that amounted to more than 'Hello world!' or a calculator.
Digressing to my point though, I started rewriting almost the entire original program, and in an effort to clean things up, started using a map to hold the keys and values (IR codes), and to further organize it, put the assignments inside of a function (IR_generateMap()), but I'm getting an error when I compile it.
C:\Users\trevo\Documents\Arduino\improvedIRRemote\improvedIRRemote.ino: In function 'void IRLoop(bool)':
improvedIRRemote:78: error: call to non-constexpr function 'std::map<Key, T, Compare, Allocator>::reference std::map<Key, T, Compare, Allocator>::operator[](const key_type&) [with Key = std::basic_string<char>; T = int; Compare = std::less<std::basic_string<char> >; Allocator = std::allocator<int>; std::map<Key, T, Compare, Allocator>::reference = int&; std::map<Key, T, Compare, Allocator>::key_type = std::basic_string<char>]'
case IRCodes["Power Button"]:
^
improvedIRRemote:78: error: call to non-constexpr function 'std::map<Key, T, Compare, Allocator>::reference std::map<Key, T, Compare, Allocator>::operator[](const key_type&) [with Key = std::basic_string<char>; T = int; Compare = std::less<std::basic_string<char> >; Allocator = std::allocator<int>; std::map<Key, T, Compare, Allocator>::reference = int&; std::map<Key, T, Compare, Allocator>::key_type = std::basic_string<char>]'
exit status 1
call to non-constexpr function 'std::map<Key, T, Compare, Allocator>::reference std::map<Key, T, Compare, Allocator>::operator[](const key_type&) [with Key = std::basic_string<char>; T = int; Compare = std::less<std::basic_string<char> >; Allocator = std::allocator<int>; std::map<Key, T, Compare, Allocator>::reference = int&; std::map<Key, T, Compare, Allocator>::key_type = std::basic_string<char>]'
I've looked up and attempted to understand errors with non-constexpr calls, but to be perfectly honest, I don't understand how what I'm trying to do with the map relates to the problems being described in the posts that deal with said error.
#include <IRremote.h>
#include <StandardCplusplus.h>
#include <map>
//Variables responsible for recieving and decoding IR signals/codes.
IRrecv receiver(10); //IR receiver initialization.
decode_results results; //Object that is responsible for decoding the IR signal.
//Variables responsible for tracking channel changing.
int channel = 1; //The active channel.
int desiredChannel = ""; //The string that is used to concatenate the numbers pressed on the remote keypad together.
int channelEnterDelay = 4000; //The delay between the last time a number was pressed on the remote keypad and when the desiredChannel is cleared.
unsigned long channelEnterStartTime = 0; //The time in which that last number was pressed on the remote keypad.
String intConverter; //The string responsible for casting an integer to a string.
//Variables responsible for tracking volume changing.
int volume = 50; //The current volume.
int lastVolume = 50; //Holds the value of the volume previous to the volume being muted.
bool isMuted = false; //Whether or not the sound has been muted.
//Map responsible for the setting and getting of IR codes and their respective keys.
const std::map<std::string, int> IRCodes;
//Miscellanious Stuff - mostly waiting for depreciation.
int IRFlasherPin = 8;
int mode = 0;
int IRFlasherBlinkRate = 10;
//Debug mode shows channel switching info when entering from the remote keypad, turn it off to declutter the serial feed if it is not being used.
bool DEBUG_MODE = false;
void setup() {
receiver.enableIRIn(); //Tells the receiver to start listening for IR communication.
pinMode(IRFlasherPin, OUTPUT); //Configuring the pin that flashes upon recieving the 'excess communication' IR code.
Serial.begin(9600); //Begins serial communication at 9600 baud.
IR_generateMap(); //Sets all of the values for the map of IR keys and values.
//Ready message.
Serial.println("The Arduino is ON and ready for communication.");
if (DEBUG_MODE) { Serial.println("Also please note that debug mode has been preemptively enabled. The serial monitor can be expected to be much more cluttered than normal. To disable this, press the 'U/SD' button on the remote."); }
Serial.println();
}
void loop() {
//Pre-loop checks.
//empty
IRLoop(true);
}
void IRLoop(bool toldToContinueLooking) {
if (receiver.decode(&results)) {
switch(results.value) {
case IRCodes["Power Button"]:
Serial.println("Power Toggle");
break;
default:
if (DEBUG_MODE) {
Serial.print("Extraneous code: ");
Serial.print(results.value);
}
break;
}
}
if (toldToContinueLooking) { receiver.resume(); }
}
void IR_generateMap() {
//General Keys
IRCodes["Power Button"] = 16753245;
IRCodes["Mode Button"] = 16736925;
IRCodes["Back Button"] = 16750695;
IRCodes["EQ Button"] = 16769055;
IRCodes["USD Button"] = 16756815;
//Media Keys
IRCodes["PlayPause Button"] = 16720605;
IRCodes["Rewind Button"] = 16712445;
IRCodes["Fast Forward Button"] = 16761405;
//Volume Keys
IRCodes["Mute Button"] = 16769565;
IRCodes["Minus Button"] = 16754775;
IRCodes["Plus Button"] = 16748655;
//Numpad Keys
IRCodes["Numpad 0"] = 16738455;
IRCodes["Numpad 1"] = 16724175;
IRCodes["Numpad 2"] = 16718055;
IRCodes["Numpad 3"] = 16743045;
IRCodes["Numpad 4"] = 16716015;
IRCodes["Numpad 5"] = 16726215;
IRCodes["Numpad 6"] = 16734885;
IRCodes["Numpad 7"] = 16728765;
IRCodes["Numpad 8"] = 16730805;
IRCodes["Numpad 9"] = 16732845;
//Non-Key Codes
IRCodes["Excess Communication"] = 4294967295;
}
Can someone explain what I'm doing wrong to me in terms that someone of my early C++ knowledge-base would understand?
The expression in the 'case' must be compile time constant. Just use an if/else construction instead and it should work.
Thomas
I'd go in opposite way by using map to decode IR Code to handler function or by using enum. Something like this:
#include <StandardCplusplus.h>
#include <map>
#include <functional>
void power_key();
void num_key0();
void num_key1();
void num_key2();
void num_key3();
void num_key4();
void num_key5();
void num_key6();
void num_key7();
void num_key8();
void num_key9();
void num_key(int8_t);
typedef void(*handler_t)();
std::map<uint32_t, handler_t> keys;
void setup() {
keys[16753245UL] = power_key;
keys[16738455UL] = num_key0;
keys[16724175UL] = num_key1;
keys[16718055UL] = num_key2;
keys[16743045UL] = num_key3;
keys[16716015UL] = num_key4;
keys[16726215UL] = num_key5;
keys[16734885UL] = num_key6;
keys[16728765UL] = num_key7;
keys[16730805UL] = num_key8;
keys[16732845UL] = num_key9;
Serial.begin(57600);
}
void loop() {
uint32_t recvd_code = 16753245UL; // literal value, for testing purpose without IR receiver and remote
auto iter = keys.find(recvd_code); // find received code and execute it
if (iter != keys.end()) {
iter->second();
} else {
Serial.print(F("IR Code "));
Serial.print(recvd_code);
Serial.println(F("not found"));
}
delay(1000);
}
void power_key() {
Serial.println(F("Power key pressed"));
}
void num_key0() { num_key(0); }
void num_key1() { num_key(1); }
void num_key2() { num_key(2); }
void num_key3() { num_key(3); }
void num_key4() { num_key(4); }
void num_key5() { num_key(5); }
void num_key6() { num_key(6); }
void num_key7() { num_key(7); }
void num_key8() { num_key(8); }
void num_key9() { num_key(9); }
void num_key(int8_t num) {
Serial.print(F("Numeric key pressed: "));
Serial.println(num);
}
Initializer list somehow didin't work, so initialization must be done in setup and map can't be const.