Я пытаюсь создать функцию с помощью cpp11, которая экспортирует список с тремя аргументами:
list myCallBack::myRepresentation() const {
writable::list out;
out.push_back({"x"_nm = writable::integers(x)});
out.push_back({"y"_nm = writable::doubles(y)});
out.push_back({"z"_nm = as_sexp(z)});
return out;
}
поскольку z имеет тип cpp11::function, я не уверен, как правильно включить его в свой список.
Я получаю ошибку:
error: no matching function for call to ‘as_sexp(cpp11::function&)’
Я пробовал разные комбинации, которые приводили к одной и той же ошибке.
_nm означает «именный» в официальном синтаксисе cpp11 (https://cpp11.r-lib.org/articles/cpp11.html#vectors-stl)
writable:: также является частью официальной документации и должен быть объявлен для записи чего-либо на лету или когда нам понадобится отредактировать этот объект позже (в противном случае объект доступен только для чтения, как это было объяснено здесь https: //cpp11.r-lib.org/articles/converting.html#vectors)
Полный журнал ошибок
Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c callback_registry.cpp -o callback_registry.o
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:3,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/R.hpp:12: warning: "STRICT_R_HEADERS" redefined
12 | #define STRICT_R_HEADERS
|
: note: this is the location of the previous definition
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/r_vector.hpp:19,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/list.hpp:9,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/data_frame.hpp:12,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:7,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: error: no matching function for call to ‘as_sexp(cpp11::function&)’
22 | value_ = as_sexp(rhs);
| ~~~~~~~^~~~~
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:5,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: note: candidate: ‘template cpp11::enable_if_integral cpp11::as_sexp(T)’
207 | enable_if_integral as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool C = false; R = SEXPREC*]’:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:50:7: required by substitution of ‘template using enable_if_integral = cpp11::enable_if_t [with T = cpp11::function; R = SEXPREC*]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: required by substitution of ‘template cpp11::enable_if_integral cpp11::as_sexp(T) [with T = cpp11::function]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: required from ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:16:7: error: no type named ‘type’ in ‘struct std::enable_if’
16 | using enable_if_t = typename std::enable_if::type;
| ^~~~~~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: note: candidate: ‘template cpp11::enable_if_floating_point cpp11::as_sexp(T)’
212 | enable_if_floating_point as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp: In substitution of ‘template using enable_if_floating_point = typename std::enable_if::type [with T = cpp11::function; R = SEXPREC*]’:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: required by substitution of ‘template cpp11::enable_if_floating_point cpp11::as_sexp(T) [with T = cpp11::function]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: required from ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:56:7: error: no type named ‘type’ in ‘struct std::enable_if’
56 | using enable_if_floating_point =
| ^~~~~~~~~~~~~~~~~~~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:217:25: note: candidate: ‘template cpp11::enable_if_bool cpp11::as_sexp(T)’
217 | enable_if_bool as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:217:25: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:222:29: note: candidate: ‘template cpp11::enable_if_c_string cpp11::as_sexp(T)’
222 | enable_if_c_string as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:222:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:227:31: note: candidate: ‘template cpp11::enable_if_std_string cpp11::as_sexp(const T&)’
227 | enable_if_std_string as_sexp(const T& from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:227:31: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:233:29: note: candidate: ‘template cpp11::enable_if_integral cpp11::as_sexp(const Container&)’
233 | enable_if_integral as_sexp(const Container& from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:233:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:231:31: error: no type named ‘value_type’ in ‘class cpp11::function’
231 | template
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-a-list
Экспортировать объект типа функции в список ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1730684563
Anonymous
Я пытаюсь создать функцию с помощью cpp11, которая экспортирует список с тремя аргументами:
list myCallBack::myRepresentation() const {
writable::list out;
out.push_back({"x"_nm = writable::integers(x)});
out.push_back({"y"_nm = writable::doubles(y)});
out.push_back({"z"_nm = as_sexp(z)});
return out;
}
поскольку z имеет тип cpp11::function, я не уверен, как правильно включить его в свой список.
Я получаю ошибку:
error: no matching function for call to ‘as_sexp(cpp11::function&)’
Я пробовал разные комбинации, которые приводили к одной и той же ошибке.
_nm означает «именный» в официальном синтаксисе cpp11 (https://cpp11.r-lib.org/articles/cpp11.html#vectors-stl)
writable:: также является частью официальной документации и должен быть объявлен для записи чего-либо на лету или когда нам понадобится отредактировать этот объект позже (в противном случае объект доступен только для чтения, как это было объяснено здесь https: //cpp11.r-lib.org/articles/converting.html#vectors)
Полный журнал ошибок
Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c callback_registry.cpp -o callback_registry.o
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:3,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/R.hpp:12: warning: "STRICT_R_HEADERS" redefined
12 | #define STRICT_R_HEADERS
|
: note: this is the location of the previous definition
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/r_vector.hpp:19,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/list.hpp:9,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/data_frame.hpp:12,
from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:7,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: error: no matching function for call to ‘as_sexp(cpp11::function&)’
22 | value_ = as_sexp(rhs);
| ~~~~~~~^~~~~
In file included from /home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11.hpp:5,
from callback_registry.h:4,
from callback_registry.cpp:6:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: note: candidate: ‘template cpp11::enable_if_integral cpp11::as_sexp(T)’
207 | enable_if_integral as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool C = false; R = SEXPREC*]’:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:50:7: required by substitution of ‘template using enable_if_integral = cpp11::enable_if_t [with T = cpp11::function; R = SEXPREC*]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:207:29: required by substitution of ‘template cpp11::enable_if_integral cpp11::as_sexp(T) [with T = cpp11::function]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: required from ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:16:7: error: no type named ‘type’ in ‘struct std::enable_if’
16 | using enable_if_t = typename std::enable_if::type;
| ^~~~~~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: note: candidate: ‘template cpp11::enable_if_floating_point cpp11::as_sexp(T)’
212 | enable_if_floating_point as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp: In substitution of ‘template using enable_if_floating_point = typename std::enable_if::type [with T = cpp11::function; R = SEXPREC*]’:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:212:35: required by substitution of ‘template cpp11::enable_if_floating_point cpp11::as_sexp(T) [with T = cpp11::function]’
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp:22:21: required from ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:56:7: error: no type named ‘type’ in ‘struct std::enable_if’
56 | using enable_if_floating_point =
| ^~~~~~~~~~~~~~~~~~~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/named_arg.hpp: In instantiation of ‘cpp11::named_arg& cpp11::named_arg::operator=(T) [with T = cpp11::function]’:
callback_registry.cpp:198:33: required from here
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:217:25: note: candidate: ‘template cpp11::enable_if_bool cpp11::as_sexp(T)’
217 | enable_if_bool as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:217:25: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:222:29: note: candidate: ‘template cpp11::enable_if_c_string cpp11::as_sexp(T)’
222 | enable_if_c_string as_sexp(T from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:222:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:227:31: note: candidate: ‘template cpp11::enable_if_std_string cpp11::as_sexp(const T&)’
227 | enable_if_std_string as_sexp(const T& from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:227:31: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:233:29: note: candidate: ‘template cpp11::enable_if_integral cpp11::as_sexp(const Container&)’
233 | enable_if_integral as_sexp(const Container& from) {
| ^~~~~~~
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:233:29: note: template argument deduction/substitution failed:
/home/pacha/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include/cpp11/as.hpp:231:31: error: no type named ‘value_type’ in ‘class cpp11::function’
231 | template
Подробнее здесь: [url]https://stackoverflow.com/questions/79153456/export-a-function-type-object-in-a-list[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия