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

  • SEARCH
  • Home
  • 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 9193953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:17:14+00:00 2026-06-17T21:17:14+00:00

I have a struct Foo . I would like to add some kind of

  • 0

I have a struct Foo.
I would like to add some kind of id (placeholder ?) to statically select from a tuple of values passed to different Foo objects.
Ideally I would not make it a template type because it will trigger many changes in other locations.

I tried adding an integer to it and use constexpr expressions (Demo)

#include <tuple>

using namespace std;

struct Foo {
private:
  const int pl;

public:
  constexpr Foo (int c) : pl(c) {}

  constexpr int place() {return pl;}

  template <typename... T>
  constexpr int extract(std::tuple<T ...> const &vals) {
    // I would like to uncomment the following but it fails compiling
    // return std::get<pl>(vals);
    return std::get<0>(vals);
  }
};

int main(void) {
   constexpr Foo f(1);
   constexpr std::tuple<int, int> test = std::make_tuple(0, 10);

   // The following passes
   static_assert(f.place() == 1, "ERROR");
   // The following fails
   static_assert(f.extract(test) == 10, "ERROR");
}

I was expecting that I could use the constexpr place() in the get<>, what am I missing?

Do I have a way out without using templates?

  • 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-06-17T21:17:16+00:00Added an answer on June 17, 2026 at 9:17 pm

    The first blocker is that std::get isn’t constexpr, so even if std::get<0> works for you, it doesn’t have to. (Credit to @Nate Kohl)

    You can try hard and write your own tuple with constexpr accessor, but this approach will fail too. Every function that is constexpr also must be callable without a constexpr argument (or constexpr this). There is currently no way to overload on constexpr.

    So, bad luck. This is impossible in C++11.

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

Sidebar

Related Questions

Question 1 I have a struct like, struct foo { int a; char c;
I have class foo that contains a std::auto_ptr member that I would like to
I have program, that has structure defined like this: struct foo { int magic;
I have a class template Z that I would like specialize when passed a
If I have a struct like so: struct example { uint16_t bar:1; uint16_t foo:1;
Suppose you have a class like template<class T> struct A { void foo() {
I would like to have a design suggestion from you. I have a set
Reading code from other posts, I'm seeing something like this. struct Foo { Foo()
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int
I have a struct that looks something like: struct foo_t { template <std::size_t x,

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.