Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 372891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:15:17+00:00 2026-05-12T14:15:17+00:00

I want to access a template List of C++ program from a Perl script

  • 0

I want to access a template List of C++ program from a Perl script and use those values.

Example code:

typedef list < Struct1  * > sturct1_list;

struct Struct2
{
    int i;
    struct1_list List1;
}

struct Struct1
{
    int j;
}

I used one swig generated api and did the following:

$myList = Struct2_struct1List_get 
print "Reference type: " . ref($myList) ;

now this prints as:

Reference type:  \_p\_std\_\_listTutils\_\_Struct1\_p\_t 

how to get the values from the structure using this?

Update from duplicate question:

in interface file i put

%template(ListStruct1) std::list< Struct1 * >;

after i generate the ".pm" file. I checked the APIs available this list.

I found

ListStuct1_size
ListStuct1_empty
ListStuct1_clear
ListStuct1_push.

I was able to use those elements. But i dont know how to access individual elements of the list using these API? or am I missing something in interface file?

UPDATED:

Is typemap possible to return the list as array here??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:15:17+00:00Added an answer on May 12, 2026 at 2:15 pm

    First of all, general info

    This tutorial shows how to do the wrapper for templates.

    The same tutorial shows how to use the module from Perl, but the perl example doesn’t touch templates.

    This SO article shows how to do that with a Vector

    Here’s a general SWIG STL documentation that seems to mention std_list.i interface.

    Second, regarding lists

    1. You can not “access” C++ list like a Perl array, by a subscript. If you wanted that, you must use a Vector as underlying type.

    2. As an alternate, create a class extending List, give it a new method which returns an element by an index, and expose that method in an interface.

    3. If you wish to access the list by finding an element, like in C++, you need to write a List interface that exposes find() method – the default one does not from reading the source code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.