# @inbounds like mechanism?

**URL:** https://discourse.julialang.org/t/inbounds-like-mechanism/4818
**Category:** General Usage
**Tags:** metaprogramming
**Created:** [July 12, 2017, 6:55pm UTC](https://discourse.julialang.org/t/inbounds-like-mechanism/4818 "2017-07-12T18:55:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [July 12, 2017, 6:55pm UTC](https://discourse.julialang.org/t/inbounds-like-mechanism/4818/1 "2017-07-12T18:55:57Z")

</div>

In the [ArgCheck](https://github.com/jw3126/ArgCheck.jl) package, there is the `@argcheck` macro that can be used to check function arguments:

```julia
julia> using ArgCheck

julia> f(x) = (@argcheck x >= 0; x)
f (generic function with 1 method)

julia> f(1)
1

julia> f(-1)
ERROR: ArgumentError: x >= 0 must hold. Got
x => -1
0 => 0

```

However in performance critical code you may not want the branch that is introduced by `@argcheck`.  
This is similar to the situation with boundschecks. Now in the case of boundschecks there is the `@inbounds` macro. It would be nice to have an analogous `@noargcheck` to suppress `@argcheck`. Is it possible to implement such a thing in a package?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [July 12, 2017, 7:31pm UTC](https://discourse.julialang.org/t/inbounds-like-mechanism/4818/2 "2017-07-12T19:31:19Z")

</div>

See [Generalizing bounds checking](https://discourse.julialang.org/t/generalizing-bounds-checking/4704)

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 12, 2017, 7:44pm UTC](https://discourse.julialang.org/t/inbounds-like-mechanism/4818/3 "2017-07-12T19:44:53Z")

</div>

You can create a shim around the macro as described in [https://github.com/KristofferC/TimerOutputs.jl/blob/master/README.md#overhead](https://github.com/KristofferC/TimerOutputs.jl/blob/master/README.md#overhead). This need to be defined in non precompiled code so you can chose at run time whether the macro should be active or not.

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [July 12, 2017, 8:52pm UTC](https://discourse.julialang.org/t/inbounds-like-mechanism/4818/4 "2017-07-12T20:52:19Z")

</div>

Or (perhaps preferably) use a `const Ref{Bool}` instead of a `Bool`, as @jameson suggested in my earlier post.
