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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:41:59+00:00 2026-05-29T09:41:59+00:00

I am used to angle brackets being used to specify a type, as a

  • 0

I am used to angle brackets being used to specify a type, as a parameter:

vector<int> vecOfInts ;

But in rapidjson, there is code like this:

document.Parse<0>(json) ;

The document.Parse method’s signature is:

template <unsigned parseFlags>
GenericDocument& Parse(const Ch* str) {
    RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
    GenericStringStream<Encoding> s(str);
    return ParseStream<parseFlags>(s);
}

I didn’t know you could pass a value inside angle brackets – thought angle brackets were used for typenames alone.

What is the code here doing, and why is he passing a value in the angle brackets?

Is this a good idea? When?

  • 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-29T09:41:59+00:00Added an answer on May 29, 2026 at 9:41 am

    There are two different factors going on here.

    First, it’s possible to define templates that are parameterized over things other than just types. For example, here’s a simple array type:

    template <typename T, size_t N> struct Array {
        T arr[N];
    };
    

    We can use this like

    Array<int, 137> myArray;
    

    We know that vector<int> and vector<double> are different types. But now we must also point out that Array<int,137> and Array<int,136> are different types.

    Second, when using templates, the compiler has to be able to figure out a value for all of the template arguments. When you’re using template classes, this is why you typically specify all the template arguments. You don’t say vector x, for example, but instead say something like vector<double> x. When using template functions, most of the time the compiler can figure out the arguments. For example, to use std::sort, you just say something like

    std::sort(v.begin(), v.end());
    

    However, you could also write

    std::sort<vector<int>::iterator>(v.begin(), v.end());
    

    to be more explicit. But sometimes, you have a template function for which not all the arguments can be figured out. In your example, we have this:

    template <unsigned parseFlags>
    GenericDocument& Parse(const Ch* str) {
        RAPIDJSON_ASSERT(!(parseFlags & kParseInsituFlag));
        GenericStringStream<Encoding> s(str);
        return ParseStream<parseFlags>(s);
    }
    

    Notice that the parseFlags template parameter can’t be deduced from just the arguments of the function. As a result, to call the function, you must specify the template parameter, since otherwise the compiler can’t figure it out. That’s why you’d write something like

    Parse<0>(myString);
    

    Here, the 0 is a template argument (resolved at compile-time), and myString is the actual argument (resolved at run-time).

    You can actually have methods that combine a bit of type inference and a bit of explicit type parameters. For example, in Boost, there’s a function lexical_cast that can do conversions to and from string types. The function signature to convert from a non-string type to a string type is

    template <typename Target, typename Source>
        Target lexical_cast(const Source& arg);
    

    Here, if you call lexical_cast, the compiler can figure out what Source is, but it can’t deduce Target without some hints. To use lexical_cast, therefore, you’d write something like

    std::string myString = boost::lexical_cast<std::string>(toConvertToString);
    

    More generally, the compiler says that you have to specify some number of template arguments (optionally 0), and it will try to deduce the rest. If it can, great! If not, it’s a compile-time error. Using this, if you’d like, you could write a function like

    template <int IntArgument, typename TypeArgment>
        void DoSomething(const TypeArgument& t) {
           /* ... */
    }
    

    To call this function, you’d have to invoke it like this:

    DoSomething<intArg>(otherArg);
    

    Here, this works because you have to explicitly tell the compiler what IntArgument is, but then the compiler can deduce TypeArgument from the type of the argument to DoSomething.

    Hope this helps!

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

Sidebar

Related Questions

Related: Reason for using non-type template parameter instead of regular parameter? What is angle
Never used a cache like this before. The problem is that I want to
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
The Following code is used as an example as an into to Generics. //
I have used to draw pie chart using canvas.. There are approximately 10 arcs
Is there a way to target only Chrome on Mac ONLY? I have used:
I used the codes below to rotate an UIImage double angle = -90; NSData
Been trying to get the relative angle of two vectors. However what the code
I'm not new to C++ but I am used to running a g++ compiler
Hey, This issue was addressed before but not in this angle. I'm trying to

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.