Rcpp Version 1.1.2
Loading...
Searching...
No Matches
lgrow.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// lgrow.h: Rcpp R/C++ interface class library -- grow a (LANGSXP) pairlist
4//
5// Copyright (C) 2010 - 2025 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp_lgrow_h
23#define Rcpp_lgrow_h
24
25#include <RcppCommon.h>
26#include <Rcpp/Named.h>
27
28namespace Rcpp {
29
30inline SEXP lgrow(SEXP head, SEXP tail) {
31 return Rf_lcons(head, tail);
32}
33
34namespace internal {
35
36// for Named objects
37template <typename T>
38inline SEXP lgrow__dispatch(Rcpp::traits::true_type, const T& head, SEXP tail) {
39 Shield<SEXP> y(wrap(head.object));
40 Shield<SEXP> x(Rf_lcons(y, tail));
41 SEXP headNameSym = Rf_install(head.name.c_str());
42 SET_TAG(x, headNameSym);
43 return x;
44}
45
46// for all other objects
47template <typename T>
48inline SEXP lgrow__dispatch(Rcpp::traits::false_type, const T& head, SEXP tail) {
49 return lgrow(wrap(head), tail);
50}
51
52} // internal
53
54template <typename T>
55SEXP lgrow(const T& head, SEXP tail) {
58}
59
60inline SEXP lgrow(const char* head, SEXP tail) {
62 return lgrow(Rf_mkString(head), y);
63}
64
65template <typename T1>
66SEXP langlist(const T1& t1) {
67 return lgrow(t1, R_NilValue);
68}
69
70template <typename T, typename... TArgs>
71SEXP langlist(const T& t1, const TArgs&... args) {
72 return lgrow(t1, langlist(args...));
73}
74
75} // namespace Rcpp
76
77#endif
SEXP lgrow__dispatch(Rcpp::traits::true_type, const T &head, SEXP tail)
Definition lgrow.h:38
integral_constant< bool, true > true_type
integral_constant< bool, false > false_type
Rcpp API.
Definition algo.h:28
sugar::Tail< RTYPE, NA, T > tail(const VectorBase< RTYPE, NA, T > &t, R_xlen_t n)
Definition tail.h:56
SEXP lgrow(SEXP head, SEXP tail)
Definition lgrow.h:30
sugar::Head< RTYPE, NA, T > head(const VectorBase< RTYPE, NA, T > &t, R_xlen_t n)
Definition head.h:53
SEXP langlist(const T1 &t1)
Definition lgrow.h:66
SEXP wrap(const Date &date)
Definition Date.h:38