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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:46:46+00:00 2026-06-05T03:46:46+00:00

I am having some trouble wrapping my head around noexcept. template <int SIZE> int

  • 0

I am having some trouble wrapping my head around noexcept.

template <int SIZE>
int pop(int idx) noexcept(noexcept(SIZE > 0)) // this is what I dont understand
{
  if (idx <= 0)
    throw std::out_of_range("My array doesnt go that high");
  return idx;
}

This is just a simple function, but you see how it only throws an exception when idx <= 0, I dont understand. So in my specification, noexcept(idx > 0), I am trying to tell the compilier this function ONLY throws no exceptions if idx > 0. Am I doing this right?

Any help is appreciated, I hope I am explaining it right. Just some simple explanation would be great.

  • 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-05T03:46:47+00:00Added an answer on June 5, 2026 at 3:46 am

    Actually the noexept specification expects a constant expression, not a runtime expression. You have used the noexcept specificatiom together with the noexcept operator. noexcept(idx >0) returns true as comparing two integers does not throw, and you are using that true as the argument to the noexcept specification telling the compiler your function never throws. The declaration

    int pop(int idx) noexcept(noexcept(idx > 0))
    

    says this function does not throw as long as idx > 0 does not throw, which is always the case for an int.

    Update: Now you’ve changed the code in the question so that idx is a non-type template argument, however the same reasoning applies. Comparing ints never throws.

    What you seem to be trying to do cannot be done in C++. That is, specify whether a function throws or not based on its runtime arguments.

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

Sidebar

Related Questions

I am currently having some trouble wrapping my head around this issue. I had
Having a bit of trouble wrapping my head around Qtimer this morning. Here's the
I am having some trouble wrapping my head around virtual proxies. I have read
I'm new to backbone.js and having some trouble wrapping my head around an issue
I'm having some troubles wrapping my head around how to go about parsing some
I'm having trouble wrapping my head around a query. I have the following 3
I'm having trouble wrapping my head around Events and their Handlers in general. I
I'm having trouble wrapping my head around what should be a simple solution. I
I'm having some troubles wrapping my head around lxml. I have some html I
I am having trouble wrapping my head around the spark skin class in relation

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.