I am
using
std::pair
when
I
try
to insert integer data
as
value
it
is
working well but
when
I
try
to use
string
data
as
value
it
is
not working details below
#define __CONFIGSERVICE_H__
#include
"
toml.hpp"
#include <typeinfo>
#include <iostream>
#include <ctype.h>
#include <cstring>
#include <vector>
#include <bits/stdc++.h>
#include <boost/algorithm/string.hpp>
#include <variant>
#include
"
configservice.hpp"
using
namespace
std;
ConfigService config;
template <typename valueType, typename objectType>
void
testing(
const
std::
string
&arrName, valueType &var)
toml::
value
allData = toml::parse(
"
../data.toml"
);
for
(
const
auto &obj : allData.as_array())
objectType newObj;
for
(
const
auto &[k, v] : obj.as_table())
std::unordered_map<std::
string
, variant<int,
float
,
bool
,
string
, vector<int>, vector<string>, vector<bool>>> newObj;
if
(v.is_array())
for
(
const
auto &item : v.as_array())
if
(item.is_integer())
std::pair<std::
string
, vector<int>>
object
(config.ParseToString(k), item.as_integer());
newObj.insert(
object
);
else
if
(item.is_string())
std::pair<std::
string
, vector<std::string>>
object
(k, item.as_string());
newObj.insert(
object
);
catch
(
const
exception &err)
cout << err.what() << endl;
void
test()
std::vector<std::unordered_map<std::
string
, variant<int,
float
,
bool
,
string
, vector<int>, vector<string>, vector<bool>>>>
var
;
testing<std::vector<std::unordered_map<std::
string
, variant<int,
float
,
bool
,
string
, vector<int>, vector<string>, vector<bool>>>>, std::unordered_map<std::
string
, variant<int,
float
,
bool
,
string
, vector<int>, vector<string>, vector<bool>>>>(
"
system.camera"
,
var
);
for
(
const
auto &element :
var
)
for
(auto it = element.begin(); it != element.end(); ++it)
std::cout << it->first <<
'
\n'
;
int
main(
int
argc,
char
const
*argv[])
test();
return
0
;
Traceback
| ^~~~~~
In file included
from
/usr/include/c++/9/bits/stl_algobase.h:
64
,
from
/usr/include/c++/9/bits/char_traits.h:
39
,
from
/usr/include/c++/9/ios:
40
,
from
/usr/include/c++/9/ostream:
38
,
from
/usr/include/c++/9/iostream:
39
,
from
/home/jocefyne/workspace/reactVision/rv_utils/ConfigService/main.cpp:
2
:
/usr/include/c++/9/bits/stl_pair.h:
229
:
26
: note: candidate: ‘template<class _U1,
class
_U2, typename std::enable_if<std::__and_<std::__is_implicitly_default_constructible<_U1>, std::__is_implicitly_default_constructible<_U2> >::
value
, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair()’
229
| _GLIBCXX_CONSTEXPR pair()
| ^~~~
/usr/include/c++/9/bits/stl_pair.h:
229
:
26
: note: template argument deduction/substitution failed:
In file included
from
/home/jocefyne/workspace/reactVision/rv_utils/ConfigService/main.cpp:
3
:
/home/jocefyne/workspace/reactVision/rv_utils/ConfigService/configservice.hpp:
186
:
72
: note: candidate expects
0
arguments,
2
provided
186
| std::pair<std::
string
, vector<string>>
object
(ParseToString(k), item.as_string());
| ^~~~~~
make[2]: *** [CMakeFiles/ConfigService.dir/build.make:
76
: CMakeFiles/ConfigService.dir/main.cpp.o] Error
1
make[2]: *** Waiting
for
unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:
100
: CMakeFiles/ConfigService.dir/all] Error
2
make: *** [Makefile:
136
: all] Error
2
### system.camera returns
vendor_name =
"
Raspberry"
fps =
24
supported_res = [
1280
,
720
,
active_algos = [
"
motion_detection"
,
cap_res = [
1280
,
720
,
hw_type =
"
usb"
broadcast_port =
4700
hw_path =
"
/dev/video0"
id =
"
cam1"
[[ip.motion_detection]]
dilate_iteration =
2
threshold_type =
0
threshold_max =
255
threshold =
25
gaussian_blur_mat_size =
21
active =
true
countour_max_area =
200
id =
"
cam1"
There
is
a simple example I have written and got the same error
if
u know about it then
let
me know. I am
using
TOML variant pairs vectors and a lot more you can check all headers.
When i use ```std::pair<std::
string
, vector<int>>....``` it
is
working but at the same time
if
i use ```std::pair<std::
string
, vector<string>>``` it
is
not working
as
i want
What I have tried:
std::variant - cppreference.com
[
^
]
/home/jocefyne/workspace/reactVision/rv_utils/ConfigService/configservice.hpp:186:72: note: candidate expects 0 arguments, 2 provided
You need to look at the line referenced in this error message.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
std::pair<std::string, vector<int>>
....``` it is working but at the same time if i use ```std::pair<std::string, vector<string>>
``` it is not working as i want"The following code works fine for both types:
You need to show your "simple" example.