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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:45:22+00:00 2026-06-18T15:45:22+00:00

I currently have a class template that takes a series of types. Each type

  • 0

I currently have a class template that takes a series of types. Each type may need to be instantiated with the class, itself. What I currently have is something like this:

template <typename... Types>
struct TypeList; // Not defined

struct Placeholder; // Not defined

template <typename Types, typename AnotherType = Default>
class MyClass
{
    // ...
};

You can then use it like this:

typedef MyClass<TypeList<Container1<Placeholder>, Container2<std::string,
        Placeholder>, OtherType>, OptionalType> MyTypedef;
MyTypedef my_object;

MyClass will replace appearances of Placeholder with itself, use the resulting types, and all is well.

The problem occurs when I try to do something like either of these:

MyTypedef *my_ptr = &my_object;
my_free_function(my_object);

Both of these cause a compiler error, because the compiler tries to instantiate Container1<Placeholder> and Container2<std::string, Placeholder> to do argument dependent lookup (ADL), and this instantiation with Placeholder, itself, fails.

I know it is possible to avoid ADL by doing, e.g.,

MyTypedef *my_ptr = std::addressof(my_object);
(my_free_function)(my_object);

However, I don’t want to burden the user of MyClass with having to constantly suppress ADL. Is there another, straightforward way to have the user provide a list of types without those types being used for ADL?

  • 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-18T15:45:23+00:00Added an answer on June 18, 2026 at 3:45 pm

    Okay, I got everything working. The trick was to use a dependent type instead of using a template, directly. My final solution was to define TypeList as follows:

    template <typename... Types>
    struct TypeList
    {
    private:
        struct Holder
        {
        private:
            typedef TypeList<Types...> InnerTypeList;
            template <typename Types, typename AnotherType>
            friend class MyClass;
        };
    public:
        typedef Holder type;
    };
    

    Then, the users of MyClass can do

    typedef MyClass<TypeList<Container1<Placeholder>, Container2<std::string,
            Placeholder>::type, OtherType>, OptionalType> MyTypedef;
    MyTypedef my_object;
    

    Note the addition of ‘::type’

    Finally, in MyClass, I replaced

    typedef typename SubstituteType<Types, Placeholder, MyClass>::type InternalTypeList;
    

    with

    typedef typename SubstituteType<Types::InnerTypeList, Placeholder, MyClass>::type
            InternalTypeList;
    

    giving me the same type for InternalTypeList as before.

    Because the dependent type Holder has no template parameters of it’s own, the compiler doesn’t have to instantiate the Placeholder types for ADL purposes, and everything works properly.

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

Sidebar

Related Questions

Currently I have a class that is extending the ListActivity class. I need to
I currently have service classes that look something like this public class UserService :
We have some code that looks like this: class Serializer { public: template<class Type>
I currently have a constructor for a class that is : template<class TX, class
I currently have a class called clientActivity that contains a finger paintig activity that
I currently have a class where I need accomplish the equivalent of the following
Currently I have a class that looks like this: public class MyClass : IMyClass
We currently have a utilities class that handles a lot of string formatting, date
I currently have a helper class that I am using to obfuscate a static
I currently have a need for a custom ListViewItem class - let's call it

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.