[Insight-users] Concept checking

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Jan 4 15:23:48 EST 2012


The signature of the concept is as follows:

template< typename T1, typename T2 = T1, typename T3 = T1 >
struct BracketOperator...

Using grep I found this usage in ITK:

 itkConceptMacro( OutputPixelShouldHaveBracketOperator,
                   ( Concept::BracketOperator<
                       OutputPixelType,
                       unsigned int,
                       typename OutputPixelType::ValueType > ) );


So it looks like you should specify more template arguments to the concept.

You are correct that nameOfCheck can be any unique name for the scope the Concept Macro is in.

Hope this helps,
Brad



On Jan 4, 2012, at 3:07 PM, David Doria wrote:

> I am trying to ensure the type that my function is instantiated with has a certainly property. I tried this:
> 
> #include <itkConceptChecking.h>
> #include <itkImage.h>
> #include <itkVectorImage.h>
> 
> template <typename T>
> void MyFunction(const T& image)
> {
>   // MyFunction should only accept types that have an operator[]
>   itkConceptMacro( nameOfCheck, ( itk::Concept::BracketOperator< T> ) ); // here, 'nameOfCheck can be anything, right?
> 
> }
> 
> int main(int, char*[])
> {
>   itk::VariableLengthVector<float> a;
>   a[0] = 1;
>   MyFunction(a);
> 
>   int b;
> //   MyFunction(b);
> 
>   return EXIT_SUCCESS;
> }
> 
> -----------
> 
> VariableLengthVector definitely has operator[], as shown with the assignment a[0] = 1. However, the call to MyFunction(a) produces compiler errors that say "no match for operator[]". Can anyone explain what I'm doing wrong here?
> 
> Thanks,
> 
> David
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

========================================================
Bradley Lowekamp  
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120104/3c8e5b19/attachment.htm>


More information about the Insight-users mailing list