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 6220083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:53:45+00:00 2026-05-24T07:53:45+00:00

Given a Vertex as: class VertexProps { public: int id; float frame; string name;

  • 0

Given a Vertex as:

class VertexProps {
  public:
    int id;
    float frame;
    string name;
};

I have initialized my boost graph using bundled properties. I know I can get the frame by using:

std::cout << "Vertex frame: " << boost::get(&VertexProps::frame, graph, vertex) << std::endl;
//Need to make this work: float frame = boost::get(&VertexProps::frame, graph, vertex);
//graph is a boost::adjacency_list and vertex is a boost::vertex_descriptor

However, I want to write a more general function or wrapper such that:

std::vector<float> frames;
std::string prop_name = "frame";
float frame = graph.get_vertex_prop(vertex, prop_name);
frames.push_back(frame);

I was hoping for something along the lines:

typedef boost::variant< int, unsigned int, float, std::string > PropValType;
typedef boost::vertex_bundle_type<Graph>::type PropIdType;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;

PropValType get_vertex_prop(Vertex& v, PropIdType pname)
{
  boost::get(pname, graph, v);
  //If pname = frame then return value as float (or cast boost::variant to float)
  //If pname = name then return value as a string
}

I want to avoid something like:

PropValType get_vertex_prop(Vertex& v, std::string pname) {
 if (pname == "frame") {
   boost::get(&VertexProps::frame, graph, v)
   //return value as float
 }
 if (...)
}
  • 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-24T07:53:46+00:00Added an answer on May 24, 2026 at 7:53 am

    There is no way to do that with out any macro magic at compile time. C++ doesn’t allow string literals as non-type template parameters and has very slim reflection capabilities.

    The solution you propose (and want to avoid) requires some work at run-time and should generally be avoided.

    The macro solution would be along those lines:

    #define MY_GET(v, pname) boost::get(&VertexProps##pname, graph, v)
    PropValType v = MY_GET(v, frame);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a 'vertex' class which, when combined, form a graph. these vertices
In Java, I have a subclass Vertex of the Java3D class Point3f . Now
Given an undirected cyclic planar graph G(V,E) with vertex weights W(V), a fixed plane
Given a latitude and longitude, what is the easiest way to find the name
I have to solve the following constructor for a BinaryTree class in java: BinaryTree(GeneralTree<T>
Suppose I have a function like this: def getNeighbors(vertex) which returns a list of
Given a directed graph with weighted edges, what algorithm can be used to give
To get the center, I have tried, for each vertex, to add to the
Given a triangle vertex defined with three 3D points, how do you calculate the
I can't figure out what is up with this. I have a Scene class

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.